From d8c89ceeefff0faa5c456c99752041fc9daba515 Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Thu, 19 Apr 2018 19:00:35 -0700 Subject: [PATCH] deps: fix libuv registry API error handling 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: https://github.com/libuv/libuv/pull/1811 PR-URL: https://github.com/nodejs/node-chakracore/pull/517 Reviewed-By: Seth Brenith --- deps/uv/src/win/util.c | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index 3c1d9bed1db..5f54382f729 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -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; @@ -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; }