From a926a26f0c69ab10e3f9a5335b84b4ab4ac91db1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 11 Mar 2023 13:43:36 -0800 Subject: [PATCH] Fix change_field() buffer underrun * lib/fields.c (change_field): Don't point before array start; that has undefined behavior. Signed-off-by: Paul Eggert Signed-off-by: Alejandro Colomar Reviewed-by: Iker Pedrosa --- lib/fields.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fields.c b/lib/fields.c index fa5fd156..640be931 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -91,8 +91,9 @@ void change_field (char *buf, size_t maxsize, const char *prompt) * entering a space. --marekm */ - while (--cp >= newf && isspace (*cp)); - cp++; + while (newf < cp && isspace (cp[-1])) { + cp--; + } *cp = '\0'; cp = newf;