From: Chris Hofstaedtler <zeha@debian.org>
To: util-linux@vger.kernel.org
Cc: Chris Hofstaedtler <zeha@debian.org>, Emanuele Rocca <ema@debian.org>
Subject: [PATCH] setterm: avoid restoring flags from uninitialized memory
Date: Tue, 31 Oct 2023 14:52:26 +0100 [thread overview]
Message-ID: <20231031135226.10243-1-zeha@debian.org> (raw)
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
next reply other threads:[~2023-10-31 14:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 13:52 Chris Hofstaedtler [this message]
2023-11-01 2:55 ` [PATCH] setterm: avoid restoring flags from uninitialized memory Dragan Simic
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=20231031135226.10243-1-zeha@debian.org \
--to=zeha@debian.org \
--cc=ema@debian.org \
--cc=util-linux@vger.kernel.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