kgdbts: Read buffer overflow
authorRoel Kluin <roel.kluin@gmail.com>
Fri, 11 Dec 2009 14:43:15 +0000 (08:43 -0600)
committerJason Wessel <jason.wessel@windriver.com>
Fri, 11 Dec 2009 14:43:15 +0000 (08:43 -0600)
Prevent write to put_buf[BUFMAX] in kgdb test suite.

If put_buf_cnt was BUFMAX - 1 at the earlier test,
`\0' is written to put_buf[BUFMAX].

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
drivers/misc/kgdbts.c

index e4ff50b..2ab0492 100644 (file)
@@ -712,6 +712,12 @@ static int run_simple_test(int is_get_char, int chr)
 
        /* End of packet == #XX so look for the '#' */
        if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') {
+               if (put_buf_cnt >= BUFMAX) {
+                       eprintk("kgdbts: ERROR: put buffer overflow on"
+                               " '%s' line %i\n", ts.name, ts.idx);
+                       put_buf_cnt = 0;
+                       return 0;
+               }
                put_buf[put_buf_cnt] = '\0';
                v2printk("put%i: %s\n", ts.idx, put_buf);
                /* Trigger check here */