Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] setterm: avoid restoring flags from uninitialized memory
@ 2023-10-31 13:52 Chris Hofstaedtler
  2023-11-01  2:55 ` Dragan Simic
  2023-11-01 12:04 ` Karel Zak
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Hofstaedtler @ 2023-10-31 13:52 UTC (permalink / raw)
  To: util-linux; +Cc: Chris Hofstaedtler, Emanuele Rocca

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>
Tested-by: Emanuele Rocca <ema@debian.org>
---
 term-utils/setterm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 1bf9a5bb4..92bf75a46 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"));
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] setterm: avoid restoring flags from uninitialized memory
  2023-10-31 13:52 [PATCH] setterm: avoid restoring flags from uninitialized memory Chris Hofstaedtler
@ 2023-11-01  2:55 ` Dragan Simic
  2023-11-01 12:04 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Dragan Simic @ 2023-11-01  2:55 UTC (permalink / raw)
  To: Chris Hofstaedtler; +Cc: util-linux, Emanuele Rocca

On 2023-10-31 14:52, Chris Hofstaedtler wrote:
> 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>
> Tested-by: Emanuele Rocca <ema@debian.org>

Looks good to me, FWIW.

> ---
>  term-utils/setterm.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/term-utils/setterm.c b/term-utils/setterm.c
> index 1bf9a5bb4..92bf75a46 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"));

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] setterm: avoid restoring flags from uninitialized memory
  2023-10-31 13:52 [PATCH] setterm: avoid restoring flags from uninitialized memory Chris Hofstaedtler
  2023-11-01  2:55 ` Dragan Simic
@ 2023-11-01 12:04 ` Karel Zak
  1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2023-11-01 12:04 UTC (permalink / raw)
  To: Chris Hofstaedtler; +Cc: util-linux, Emanuele Rocca

On Tue, Oct 31, 2023 at 02:52:26PM +0100, Chris Hofstaedtler wrote:
>  term-utils/setterm.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-01 12:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-31 13:52 [PATCH] setterm: avoid restoring flags from uninitialized memory Chris Hofstaedtler
2023-11-01  2:55 ` Dragan Simic
2023-11-01 12:04 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox