]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
main/asterisk.c: ast_el_read_char 60/2060/1
authorDiederik de Groot <ddegroot@talon.nl>
Mon, 18 Jan 2016 09:49:48 +0000 (10:49 +0100)
committerMark Michelson <mmichelson@digium.com>
Thu, 21 Jan 2016 21:25:07 +0000 (15:25 -0600)
Make sure buf[res] is not accessed at res=-1 (buffer underrun).
Address Sanitizer will complain about this quite loudly.

ASTERISK-24801 #close

Change-Id: Ifcd7f691310815a31756b76067c56fba299d3ae9

main/asterisk.c

index c576c16f6be56925fbc4d4ad2eb19efd32476018..d99aaed189741a8416691b59d4d8a1f8076b35a7 100644 (file)
@@ -2808,11 +2808,12 @@ static int ast_el_read_char(EditLine *editline, char *cp)
 
                        console_print(buf, 0);
 
-                       if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (buf[res-2] == '\n'))) {
+                       if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (res >= 2 && buf[res-2] == '\n'))) {
                                *cp = CC_REFRESH;
                                return(1);
-                       } else
+                       } else {
                                lastpos = 1;
+                       }
                }
        }