From f851875ad1c1c2af345a24ea69c4d71e70ce48b4 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 8 Jan 2015 21:58:35 +0300 Subject: [PATCH 1/2] Improve Windows Registry searching for Python. Simplify logic of related functions. Make sure that all open handles are closed. Explicitly use Unicode versions of Windows API functions. Prevent max subkey length overwrite. Use Windows API style of variable names. --- src/preferences/preferences.cpp | 245 ++++++++++++++++---------------- 1 file changed, 125 insertions(+), 120 deletions(-) diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 31a0ccccb..4eeffa0ab 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -1339,145 +1339,150 @@ void Preferences::disableRecursiveDownload(bool disable) { #ifdef Q_OS_WIN namespace { -enum REG_SEARCH_TYPE {USER, SYSTEM_32BIT, SYSTEM_64BIT}; - -QStringList getRegSubkeys(const HKEY &handle) { - QStringList keys; - DWORD subkeys_count = 0; - DWORD max_subkey_len = 0; - long res = ::RegQueryInfoKey(handle, NULL, NULL, NULL, &subkeys_count, &max_subkey_len, NULL, NULL, NULL, NULL, NULL, NULL); - if (res == ERROR_SUCCESS) { - max_subkey_len++; //For null character - LPTSTR key_name = new TCHAR[max_subkey_len]; - - for (uint i=0; i Date: Sat, 10 Jan 2015 13:17:50 +0300 Subject: [PATCH 2/2] Fix heap corruption. Closes #2342. Fix heap corruption during Registry access. --- src/preferences/preferences.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 4eeffa0ab..22ca38016 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -1394,7 +1394,7 @@ QString getRegValue(HKEY handle, const QString &name = QString()) delete[] lpValueName; if (res == ERROR_SUCCESS) { - lpData[cBuffer] = 0; + lpData[cBuffer - 1] = 0; result = QString::fromWCharArray(lpData); } delete[] lpData;