printstr: check for potential integer overflow
* util.c (printstr): Check for potential integer overflow during outstr buffer size calculation.
This commit is contained in:
parent
ccee169ab6
commit
378f9c5ad0
6
util.c
6
util.c
@ -564,10 +564,14 @@ printstr(struct tcb *tcp, long addr, int len)
|
|||||||
}
|
}
|
||||||
/* Allocate static buffers if they are not allocated yet. */
|
/* Allocate static buffers if they are not allocated yet. */
|
||||||
if (!str) {
|
if (!str) {
|
||||||
|
unsigned int outstr_size = 4 * max_strlen + /*for quotes and NUL:*/ 3;
|
||||||
|
|
||||||
|
if (outstr_size / 4 != max_strlen)
|
||||||
|
die_out_of_memory();
|
||||||
str = malloc(max_strlen + 1);
|
str = malloc(max_strlen + 1);
|
||||||
if (!str)
|
if (!str)
|
||||||
die_out_of_memory();
|
die_out_of_memory();
|
||||||
outstr = malloc(4 * max_strlen + /*for quotes and NUL:*/ 3);
|
outstr = malloc(outstr_size);
|
||||||
if (!outstr)
|
if (!outstr)
|
||||||
die_out_of_memory();
|
die_out_of_memory();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user