Skip to content
Snippets Groups Projects
Commit 394ca50f authored by Zachary Turner's avatar Zachary Turner
Browse files

[Driver] Fix Windows SDK Detection

This fixes a couple of bugs in Windows SDK Detection.

1. `readFullStringValue` returns a bool, but was being compared
   with ERROR_SUCCESS.
2. `RegQueryValueExW` might return the null terminator in the
   queried value which will result in incorrect values being
   returned from `getSystemRegistryString`.

Patch By: comicfans44@gmail.com
Reviewed By: zturner
Differential Revision: http://reviews.llvm.org/D21946

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277005 91177308-0d34-0410-b5e6-96231b3b80d8
parent 28bd9c65
No related branches found
No related tags found
No related merge requests found
...@@ -114,6 +114,9 @@ static bool readFullStringValue(HKEY hkey, const char *valueName, ...@@ -114,6 +114,9 @@ static bool readFullStringValue(HKEY hkey, const char *valueName,
if (result == ERROR_SUCCESS) { if (result == ERROR_SUCCESS) {
std::wstring WideValue(reinterpret_cast<const wchar_t *>(buffer.data()), std::wstring WideValue(reinterpret_cast<const wchar_t *>(buffer.data()),
valueSize / sizeof(wchar_t)); valueSize / sizeof(wchar_t));
if (valueSize && WideValue.back() == L'\0') {
WideValue.pop_back();
}
// The destination buffer must be empty as an invariant of the conversion // The destination buffer must be empty as an invariant of the conversion
// function; but this function is sometimes called in a loop that passes in // function; but this function is sometimes called in a loop that passes in
// the same buffer, however. Simply clear it out so we can overwrite it. // the same buffer, however. Simply clear it out so we can overwrite it.
...@@ -191,8 +194,7 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName, ...@@ -191,8 +194,7 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName,
lResult = RegOpenKeyExA(hTopKey, bestName.c_str(), 0, lResult = RegOpenKeyExA(hTopKey, bestName.c_str(), 0,
KEY_READ | KEY_WOW64_32KEY, &hKey); KEY_READ | KEY_WOW64_32KEY, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == ERROR_SUCCESS) {
lResult = readFullStringValue(hKey, valueName, value); if (readFullStringValue(hKey, valueName, value)) {
if (lResult == ERROR_SUCCESS) {
bestValue = dvalue; bestValue = dvalue;
if (phValue) if (phValue)
*phValue = bestName; *phValue = bestName;
...@@ -209,8 +211,7 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName, ...@@ -209,8 +211,7 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName,
lResult = lResult =
RegOpenKeyExA(hRootKey, keyPath, 0, KEY_READ | KEY_WOW64_32KEY, &hKey); RegOpenKeyExA(hRootKey, keyPath, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
if (lResult == ERROR_SUCCESS) { if (lResult == ERROR_SUCCESS) {
lResult = readFullStringValue(hKey, valueName, value); if (readFullStringValue(hKey, valueName, value))
if (lResult == ERROR_SUCCESS)
returnValue = true; returnValue = true;
if (phValue) if (phValue)
phValue->clear(); phValue->clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment