From: Dragan Simic <dsimic@manjaro.org>
To: Chris Hofstaedtler <zeha@debian.org>
Cc: util-linux@vger.kernel.org, Emanuele Rocca <ema@debian.org>
Subject: Re: [PATCH] setterm: avoid restoring flags from uninitialized memory
Date: Wed, 01 Nov 2023 03:55:59 +0100 [thread overview]
Message-ID: <97bb06f8ada1efe436c24962f0ed8eb3@manjaro.org> (raw)
In-Reply-To: <20231031135226.10243-1-zeha@debian.org>
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"));
next prev parent reply other threads:[~2023-11-01 2:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 13:52 [PATCH] setterm: avoid restoring flags from uninitialized memory Chris Hofstaedtler
2023-11-01 2:55 ` Dragan Simic [this message]
2023-11-01 12:04 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=97bb06f8ada1efe436c24962f0ed8eb3@manjaro.org \
--to=dsimic@manjaro.org \
--cc=ema@debian.org \
--cc=util-linux@vger.kernel.org \
--cc=zeha@debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox