Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
deps: fix libuv registry API error handling
Browse files Browse the repository at this point in the history
The `Reg*` APIs on Windows don't use `GetLastError` to report failures.
The errors are returned directly from the call.

For systems which don't have one of the values `GetLastError` can end
up returning `0` to the caller, indicating success. The caller then
assumes that the data is valid and can attempt to execute on garbage
data. This change fixes the flow to correctly return the error to the
caller.

Upstream-PR: libuv/libuv#1811
PR-URL: #517
Reviewed-By: Seth Brenith <[email protected]>
  • Loading branch information
kfarnung committed Apr 22, 2018
1 parent f82e85b commit d8c89ce
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions deps/uv/src/win/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
DWORD sppi_size;
SYSTEM_INFO system_info;
DWORD cpu_count, r, i;
DWORD cpu_count, i;
NTSTATUS status;
ULONG result_size;
int err;
Expand Down Expand Up @@ -670,34 +670,33 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {

assert(len > 0 && len < ARRAY_SIZE(key_name));

r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
key_name,
0,
KEY_QUERY_VALUE,
&processor_key);
if (r != ERROR_SUCCESS) {
err = GetLastError();
err = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
key_name,
0,
KEY_QUERY_VALUE,
&processor_key);
if (err != ERROR_SUCCESS) {
goto error;
}

if (RegQueryValueExW(processor_key,
L"~MHz",
NULL,
NULL,
(BYTE*) &cpu_speed,
&cpu_speed_size) != ERROR_SUCCESS) {
err = GetLastError();
err = RegQueryValueExW(processor_key,
L"~MHz",
NULL,
NULL,
(BYTE*)&cpu_speed,
&cpu_speed_size);
if (err != ERROR_SUCCESS) {
RegCloseKey(processor_key);
goto error;
}

if (RegQueryValueExW(processor_key,
L"ProcessorNameString",
NULL,
NULL,
(BYTE*) &cpu_brand,
&cpu_brand_size) != ERROR_SUCCESS) {
err = GetLastError();
err = RegQueryValueExW(processor_key,
L"ProcessorNameString",
NULL,
NULL,
(BYTE*)&cpu_brand,
&cpu_brand_size);
if (err != ERROR_SUCCESS) {
RegCloseKey(processor_key);
goto error;
}
Expand Down

0 comments on commit d8c89ce

Please sign in to comment.