If 0 is allowed for --width it will culminate to a wraparound
due to an unsigned integer underflow when a size_t for-loop
control variable, namely 'n', is setup. n is the result of
cpuset_nbits(size) - 1, where size is set by cpuset_alloc()
which was called with 0 (width) for the @ncpus parameter that
will make it so that @size remains 0 as the calculated memory
allocation size yields zero as well. Therefore the sum for 'n'
will be -1 that wraps around to UINT_MAX and end creates a
long-lived for loop.
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* allow up to 128k masks */
width = str2unum_or_err(optarg,
10, _("invalid --width"), 128 * 1024);
+ if (width == 0)
+ errx(EXIT_FAILURE, _("invalid --width"));
break;
case 'V':
print_version(EXIT_SUCCESS);