From acba844c6ba0d72c6f37d8cbee8b343c23b05de1 Mon Sep 17 00:00:00 2001 From: David Weisgerber Date: Mon, 29 Feb 2016 15:48:47 +0100 Subject: Fixed reading REG_SZ without terminating \0 delivers garbage When reading from the registry, sometimes the string is not null terminated. In order to fix this, the preallocated QByteArray size is increased, so that there are guaranteed enough terminating \0 [Windows] Not null terminated strings are now read properly from the registry Change-Id: I95fdf42cbbb7074fcf010dd14d0241f02d3c412b Task-number: QTBUG-51382 Reviewed-by: Friedemann Kleint --- src/corelib/io/qsettings_win.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 1546219c3b..da0c4c3c14 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -484,6 +484,12 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa return false; } + // workaround for rare cases where trailing '\0' are missing in registry + if (dataType == REG_SZ || dataType == REG_EXPAND_SZ) + dataSize += 2; + else if (dataType == REG_MULTI_SZ) + dataSize += 4; + // get the value QByteArray data(dataSize, 0); res = RegQueryValueEx(handle, reinterpret_cast(rSubkeyName.utf16()), 0, 0, -- cgit v1.2.3