From: Chris Hofstaedtler Date: Tue, 31 Oct 2023 13:52:26 +0000 (+0100) Subject: setterm: avoid restoring flags from uninitialized memory X-Git-Tag: v2.39.3~24 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ec7b14a72d9893d2a8d8c7f40cd45b44c9575c9;p=thirdparty%2Futil-linux.git setterm: avoid restoring flags from uninitialized memory Depending on the used compiler and flags, previously either F_SETFL was called with 0 or with a random value. Never with the intended previous flags. [kzak@redhat.com: - tiny coding style change] Signed-off-by: Chris Hofstaedtler Tested-by: Emanuele Rocca Signed-off-by: Karel Zak --- diff --git a/term-utils/setterm.c b/term-utils/setterm.c index 22afc76163..e91abc90a8 100644 --- a/term-utils/setterm.c +++ b/term-utils/setterm.c @@ -846,7 +846,10 @@ static void tty_raw(struct termios *saved_attributes, int *saved_fl) { struct termios tattr; - fcntl(STDIN_FILENO, F_GETFL, saved_fl); + *saved_fl = fcntl(STDIN_FILENO, F_GETFL); + if (*saved_fl == -1) + err(EXIT_FAILURE, _("fcntl failed")); + tcgetattr(STDIN_FILENO, saved_attributes); fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); memcpy(&tattr, saved_attributes, sizeof(struct termios)); @@ -898,7 +901,7 @@ static int resizetty(void) ssize_t rc; struct winsize ws; struct termios saved_attributes; - int saved_fl; + int saved_fl = 0; if (!isatty(STDIN_FILENO)) errx(EXIT_FAILURE, _("stdin does not refer to a terminal"));