win,util: fix null pointer dereferencing

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 <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Tobias Nießen 2019-04-16 19:01:45 +02:00 committed by Santiago Gimeno
parent 8b87533863
commit 620be96fc4
No known key found for this signature in database
GPG Key ID: F28C3C8DA33C03BE

View File

@ -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);