From: Christian Goeschel Ndjomouo Date: Mon, 6 Apr 2026 21:07:33 +0000 (-0400) Subject: lib: (cpuset.c) dont calculate allocation size for 0 ncpus X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77df1a69f31bb845546acb229c11f8aaf71d36d8;p=thirdparty%2Futil-linux.git lib: (cpuset.c) dont calculate allocation size for 0 ncpus If ncpus is not checked against the value 0, subsequent macros CPU_ALLOC_SIZE and cpuset_nbits() will return garbage (0), which can cause issues when memory has to be allocated or initialized in callers where the size is assumed to be > 0. So let us return NULL for 0 ncpus. Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/lib/cpuset.c b/lib/cpuset.c index d64692030..b04c71a35 100644 --- a/lib/cpuset.c +++ b/lib/cpuset.c @@ -98,8 +98,10 @@ int get_max_number_of_cpus(void) */ cpu_set_t *cpuset_alloc(int ncpus, size_t *setsize, size_t *nbits) { - cpu_set_t *set = CPU_ALLOC(ncpus); + cpu_set_t *set = NULL; + if (ncpus) + set = CPU_ALLOC(ncpus); if (!set) return NULL; if (setsize)