]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib: (cpuset.c) dont calculate allocation size for 0 ncpus
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 6 Apr 2026 21:07:33 +0000 (17:07 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Tue, 7 Apr 2026 14:45:43 +0000 (10:45 -0400)
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 <cgoesc2@wgu.edu>
lib/cpuset.c

index d6469203092d244e205dcabe3e2dd15b36afae1b..b04c71a355aea353f669d347211f8de56c105ad8 100644 (file)
@@ -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)