* util.c (printstr_ex): Move the check that -s argument
does not exceed -1U / 4 ...
* strace.c (init): ... here.
* tests/options-syntax.test: Check it.
break;
case 's':
i = string_to_uint(optarg);
- if (i < 0)
+ if (i < 0 || (unsigned int) i > -1U / 4)
error_opt_arg(c, optarg);
max_strlen = i;
break;
check_h "invalid -a argument: '-42'" -a -42
check_h "invalid -O argument: '-42'" -O -42
check_h "invalid -s argument: '-42'" -s -42
+check_h "invalid -s argument: '1073741824'" -s 1073741824
check_h "invalid -I argument: '5'" -I 5
if [ -n "${UID-}" ]; then
}
/* Allocate static buffers if they are not allocated yet. */
if (!str) {
- unsigned int outstr_size = 4 * max_strlen + /*for quotes and NUL:*/ 3;
+ const unsigned int outstr_size =
+ 4 * max_strlen + /* for quotes and NUL */ 3;
+ /*
+ * We can assume that outstr_size / 4 == max_strlen
+ * since we have a guarantee that max_strlen <= -1U / 4.
+ */
- if (outstr_size / 4 != max_strlen)
- die_out_of_memory();
str = xmalloc(max_strlen + 1);
outstr = xmalloc(outstr_size);
}