From: Paul Eggert Date: Sat, 11 Mar 2023 21:43:36 +0000 (-0800) Subject: Fix change_field() buffer underrun X-Git-Tag: 4.14.0-rc1~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a926a26f0c69ab10e3f9a5335b84b4ab4ac91db1;p=thirdparty%2Fshadow.git 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 --- diff --git a/lib/fields.c b/lib/fields.c index fa5fd1567..640be931f 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;