Re: Bug#1098694: Crash in agetty due to invalid strncmp call in Trixie

Chris Hofstaedtler <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <b5ikwzm4qjyxazwnck736kqdihgjmyjbsfuikfwntaece7fmmu@oxxt7prt45jz>
* Chris Hofstaedtler <[email protected]> [250223 20:06]:
> > [..] After I sent this bug report yesterday, I also found out that
> > someone has reported what I believe is the same bug to
> > upstream a while ago ( https://github.com/util-linux/util-linux/issues/3304
> > ) but so far nobody has commented on that report.
> 
> Yeah, this seems like the same issue.

Below is a patch that works, but certainly feels dirty:


From: Chris Hofstaedtler <[email protected]>
Date: Sun, 23 Feb 2025 20:10:05 +0100
Subject: agetty: restore op->tty if getting the tty name fails

Signed-off-by: Chris Hofstaedtler <[email protected]>
---
 term-utils/agetty.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index a382313..e65c985 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -929,9 +929,11 @@ static void parse_args(int argc, char **argv, struct options *op)
 	/* resolve the tty path in case it was provided as stdin */
 	if (strcmp(op->tty, "-") == 0) {
 		op->tty_is_stdin = 1;
+		const char* tty_orig = op->tty;
 		int fd = get_terminal_name(NULL, &op->tty, NULL);
 		if (fd < 0) {
 			log_warn(_("could not get terminal name: %d"), fd);
+			op->tty = tty_orig;
 		}
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.