Skip to content

Commit

Permalink
win32: refine autostart read calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Apr 26, 2024
1 parent 763c485 commit 04ca9c8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/win32/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,27 +810,27 @@ static int get_yass_auto_start() {
return -1;
}

// If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type,
// the string may not have been stored with the proper terminating null characters.
// Therefore, even if the function returns ERROR_SUCCESS,
// the application should ensure that the string is properly terminated before using it
if (type != REG_SZ || BufferSize > kRegReadMaximumSize || BufferSize % sizeof(wchar_t) != 0) {
VLOG(1) << "[autostart] mistyped auto start entry set";
return -1;
}

output.resize(BufferSize / sizeof(wchar_t) + 2);
if (BufferSize == 0) {
VLOG(1) << "[autostart] empty auto start entry set";
return -1;
}

output.resize(BufferSize / sizeof(wchar_t) - 1);
if (::RegQueryValueExW(hkey /* HKEY */, valueName /* lpValueName */, nullptr /* lpReserved */, &type /* lpType */,
reinterpret_cast<BYTE*>(output.data()) /* lpData */,
&BufferSize /* lpcbData */) != ERROR_SUCCESS) {
VLOG(1) << "[autostart] failed to fetch auto start entry";
return -1;
}
// If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type,
// the string may not have been stored with the proper terminating null characters.
// Therefore, even if the function returns ERROR_SUCCESS,
// the application should ensure that the string is properly terminated before using it
output.reserve(BufferSize / sizeof(wchar_t));
// removing trailing space
while (!output.empty() && output.back() == L'\0') {
output.resize(output.size() - 1);
}

VLOG(2) << "[autostart] previous autostart entry: " << SysWideToUTF8(output);

Expand Down

0 comments on commit 04ca9c8

Please sign in to comment.