Skip to content

Commit

Permalink
Avoid going past the allocation in find_windows_kit_root()
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli committed Feb 15, 2022
1 parent 2600d1b commit 5ceabed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/vswhom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ static wchar_t *find_windows_kit_root(HKEY key, const wchar_t *version) {
auto rc = RegQueryValueExW(key, version, NULL, NULL, NULL, &required_length);
if (rc != 0) return NULL;

DWORD length = required_length + 2; // The +2 is for the maybe optional zero later on. Probably we are over-allocating.
wchar_t *value = (wchar_t *)malloc(length);
DWORD length = required_length + sizeof(wchar_t); // The +2 is for the maybe optional zero later on. Probably we are over-allocating.
wchar_t *value = (wchar_t *)malloc(length + sizeof(wchar_t));
if (!value) return NULL;

rc = RegQueryValueExW(key, version, NULL, NULL, (LPBYTE)value, &length); // We know that version is zero-terminated...
Expand Down

0 comments on commit 5ceabed

Please sign in to comment.