]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chfn: flush stdout before reading stdin and fix uninitialized variable
authorLorenzo Beretta <vc.net.loreb@gmail.com>
Mon, 25 Oct 2021 12:06:00 +0000 (14:06 +0200)
committerLorenzo Beretta <vc.net.loreb@gmail.com>
Mon, 25 Oct 2021 13:27:16 +0000 (15:27 +0200)
Same problem as described in https://github.com/karelzak/util-linux/pull/1481

Signed-off-by: Lorenzo Beretta <vc.net.loreb@gmail.com>
login-utils/chfn.c

index 2508e14c9db84b25635f1a04adb775db9c834ee4..ece5cdce020aeade3ace40094a5e61252d3ac10f 100644 (file)
@@ -227,7 +227,7 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question,
                           char *def_val)
 {
        int len;
-       char *buf;
+       char *buf = NULL; /* leave initialized to NULL or getline segfaults */
 #ifndef HAVE_LIBREADLINE
        size_t dummy = 0;
 #endif
@@ -242,6 +242,7 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question,
                if ((buf = readline(" ")) == NULL)
 #else
                putchar(' ');
+               fflush(stdout);
                if (getline(&buf, &dummy, stdin) < 0)
 #endif
                        errx(EXIT_FAILURE, _("Aborted."));