From 1b2a2e6737c9954ac234140bf85989c3dd99eff8 Mon Sep 17 00:00:00 2001 From: Saagar Jha Date: Sun, 16 Feb 2020 04:04:11 -0800 Subject: [PATCH] rcfile: fix an out-of-bounds read on empty lines Signed-off-by: Saagar Jha Bug existed since commit 98f038ad from a week ago. --- src/rcfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rcfile.c b/src/rcfile.c index 5213e277..895a48c9 100644 --- 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;