setterm: avoid restoring flags from uninitialized memory
authorChris Hofstaedtler <zeha@debian.org>
Mon, 30 Oct 2023 21:59:33 +0000 (22:59 +0100)
committerChris Hofstaedtler <zeha@debian.org>
Mon, 30 Oct 2023 22:02:25 +0000 (23:02 +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.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
Gbp-Pq: Topic debian
Gbp-Pq: Name setterm-resize-uninit-flags.patch

term-utils/setterm.c

index 22afc761632ed063f0a63bf545b140da517e9d7f..dfc55ab3e9334f631121ffc2a26ca0bf1fc945e1 100644 (file)
@@ -846,7 +846,7 @@ 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);
        tcgetattr(STDIN_FILENO, saved_attributes);
        fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
        memcpy(&tattr, saved_attributes, sizeof(struct termios));
@@ -898,7 +898,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"));