commit 1b2a2e6737c9954ac234140bf85989c3dd99eff8
parent 12e5c2f07da77ef6661e653df421b5df4441ba7f
Author: Saagar Jha <saagar@saagarjha.com>
Date: Sun, 16 Feb 2020 04:04:11 -0800
rcfile: fix an out-of-bounds read on empty lines
Signed-off-by: Saagar Jha <saagar@saagarjha.com>
Bug existed since commit 98f038ad from a week ago.
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -1320,7 +1320,7 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
/* Strip the terminating newline and possibly a carriage return. */
if (buffer[length - 1] == '\n')
buffer[--length] = '\0';
- if (buffer[length - 1] == '\r')
+ if (length > 0 && buffer[length - 1] == '\r')
buffer[--length] = '\0';
ptr = buffer;