Check -s argument early
* 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.
This commit is contained in:
parent
4a2a9a7cb1
commit
11621507fb
2
strace.c
2
strace.c
@ -1733,7 +1733,7 @@ init(int argc, char *argv[])
|
||||
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;
|
||||
|
@ -127,6 +127,7 @@ check_h 'piping the output and -ff are mutually exclusive' -o '!' -ff true
|
||||
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
|
||||
|
9
util.c
9
util.c
@ -759,10 +759,13 @@ printstr_ex(struct tcb *const tcp, const kernel_ulong_t addr,
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user