From d2afe7d6749bc73f88e1fea993de2e0dbb5b3565 Mon Sep 17 00:00:00 2001 From: Lyndon Nerenberg Date: Thu, 10 Apr 2014 03:52:17 -0700 Subject: [PATCH] If getln() sees a newline as its first character, it incorrectly references a character one byte before the start of its input buffer. --- uip/prompter.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/uip/prompter.c b/uip/prompter.c index 37f5960b..b43d0c74 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -329,6 +329,7 @@ getln (char *buffer, int n) { int c; char *cp; + static int quoting = 0; cp = buffer; *cp = 0; @@ -350,12 +351,13 @@ getln (char *buffer, int n) for (;;) { switch (c = getchar ()) { case EOF: + quoting = 0; clearerr (stdin); longjmp (sigenv, DONE); case '\n': - if (cp[-1] == QUOTE) { - cp[-1] = c; + if (quoting) { + *(cp - 1) = c; wtuser = 0; return 1; } @@ -365,6 +367,11 @@ getln (char *buffer, int n) return 0; default: + if (c == QUOTE) { + quoting = 1; + } else { + quoting = 0; + } if (cp < buffer + n) *cp++ = c; *cp = 0; -- 2.56.0