]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
main/asterisk.c: ast_el_read_char 59/2059/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:02 +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 901cee1c51dc34276a05b75af27557cce1b7c47d..7745d3f21e6cb9fba20c008d4d61517af6938013 100644 (file)
@@ -2577,11 +2577,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;
+                       }
                }
        }