]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setterm: avoid restoring flags from uninitialized memory
authorChris Hofstaedtler <zeha@debian.org>
Tue, 31 Oct 2023 13:52:26 +0000 (14:52 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Nov 2023 12:03:03 +0000 (13:03 +0100)
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 <zeha@debian.org>
Tested-by: Emanuele Rocca <ema@debian.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/setterm.c

index 1bf9a5bb4966fcc1268101b7e0e3b4fb32e740eb..8ec10ee5e016ea217b0fd3e6ec0b0703fad7e806 100644 (file)
@@ -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"));