]> granicus.if.org Git - strace/commitdiff
printstr: check for potential integer overflow
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 25 Mar 2012 22:56:53 +0000 (22:56 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 25 Mar 2012 22:56:53 +0000 (22:56 +0000)
* util.c (printstr): Check for potential integer overflow during outstr
buffer size calculation.

util.c

diff --git a/util.c b/util.c
index ea3488d4afa3dbdd1cb0ab35e3340378349727c0..348d77f498fdd3314f7ac3ab7a8d921e21dad487 100644 (file)
--- a/util.c
+++ b/util.c
@@ -564,10 +564,14 @@ printstr(struct tcb *tcp, long addr, int len)
        }
        /* Allocate static buffers if they are not allocated yet. */
        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);
                if (!str)
                        die_out_of_memory();
-               outstr = malloc(4 * max_strlen + /*for quotes and NUL:*/ 3);
+               outstr = malloc(outstr_size);
                if (!outstr)
                        die_out_of_memory();
        }