setterm: avoid restoring flags from uninitialized memory
PATCH 1/1 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.
Signed-off-by Chris Hofstaedtler <[email protected]>
Tested-by Emanuele Rocca <[email protected]>
--- term-utils/setterm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
term-utils/setterm.c +5 -2
@@ -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" ));
Signature · 1 line
2.42.0
Quoted 5 lines · Chris Hofstaedtler
Depending on the used compiler and flags, previously either
F_SETFLwas called with 0 or with a random value. Never with the intended previous flags.Signed-off-by Chris Hofstaedtler <[email protected]>Tested-by Emanuele Rocca <[email protected]>
Looks good to me, FWIW.
Quoted 30 lines
--- term-utils/setterm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)term-utils/setterm.c +4
-1@@ -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 );term-utils/setterm.c +1
-1memcpy (&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" ));
Quoted 2 lines · Chris Hofstaedtler
term-utils/setterm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com