From: Lorenzo Beretta Date: Mon, 25 Oct 2021 12:06:00 +0000 (+0200) Subject: chfn: flush stdout before reading stdin and fix uninitialized variable X-Git-Tag: v2.38-rc1~198 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=05907d0d9e7c85f33e168feab1eb36b464425054;p=thirdparty%2Futil-linux.git chfn: flush stdout before reading stdin and fix uninitialized variable Same problem as described in https://github.com/karelzak/util-linux/pull/1481 Signed-off-by: Lorenzo Beretta --- diff --git a/login-utils/chfn.c b/login-utils/chfn.c index 2508e14c9d..ece5cdce02 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -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."));