]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Fix change_field() buffer underrun
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Mar 2023 21:43:36 +0000 (13:43 -0800)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 28 Mar 2023 11:00:38 +0000 (13:00 +0200)
* 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>
lib/fields.c

index fa5fd1567cfcc62880353a65f5c4fb464b3c05e7..640be931f3b000e063f270ed31f0baa96270df6b 100644 (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;