From 732fb03ac6df5bb1c3cdd9cd67cd9319557403e3 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 11 Apr 2016 18:03:00 +0200 Subject: [PATCH] linux: don't abort on malformed /proc/stat Return an error instead of aborting when /proc/stat doesn't have the expected format. PR-URL: https://github.com/libuv/libuv/pull/822 Reviewed-By: Colin Ihrig --- src/unix/linux-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index 333dbe80..2d712483 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -562,7 +562,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) { char buf[1024]; if (!fgets(buf, sizeof(buf), statfile_fp)) - abort(); + return -EIO; num = 0; while (fgets(buf, sizeof(buf), statfile_fp)) { @@ -571,6 +571,9 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) { num++; } + if (num == 0) + return -EIO; + *numcpus = num; return 0; } @@ -593,9 +596,6 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { if (err < 0) goto out; - assert(numcpus != (unsigned int) -1); - assert(numcpus != 0); - err = -ENOMEM; ci = uv__calloc(numcpus, sizeof(*ci)); if (ci == NULL)