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 <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
This commit is contained in:
Paul Eggert 2023-03-11 13:43:36 -08:00 committed by Iker Pedrosa
parent 690ca8c238
commit a926a26f0c

View File

@ -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;