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 <Friedemann.Kleint@theqtcompany.com>
bb10
David Weisgerber 2016-02-29 15:48:47 +01:00
parent 82b8158022
commit acba844c6b
1 changed files with 6 additions and 0 deletions

View File

@ -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<const wchar_t *>(rSubkeyName.utf16()), 0, 0,