From 620be96fc4c7645b606348933c67dbc201f53d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 16 Apr 2019 19:01:45 +0200 Subject: [PATCH] win,util: fix null pointer dereferencing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If uv__calloc returns NULL, the function jumps to the error label and attempts to access array elements of cpu_infos (which is NULL). PR-URL: https://github.com/libuv/libuv/pull/2264 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: Saúl Ibarra Corretgé Reviewed-By: Ben Noordhuis --- src/win/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/win/util.c b/src/win/util.c index 2c107284..0e8c339d 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -703,9 +703,11 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) { return 0; error: - /* This is safe because the cpu_infos array is zeroed on allocation. */ - for (i = 0; i < cpu_count; i++) - uv__free(cpu_infos[i].model); + if (cpu_infos != NULL) { + /* This is safe because the cpu_infos array is zeroed on allocation. */ + for (i = 0; i < cpu_count; i++) + uv__free(cpu_infos[i].model); + } uv__free(cpu_infos); uv__free(sppi);