From c3f97e251ef13f24538e4e52ffe4cba01ea0e840 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 2 Jul 2024 14:43:26 +0200 Subject: [PATCH] lib/port.c: getportent(): Make sure there are at least 2 ':' in the line Otherwise, the line is invalidly formatted, and we ignore it. Closes: Signed-off-by: Alejandro Colomar --- lib/port.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/port.c b/lib/port.c index f55bc724c..cac4ba44f 100644 --- a/lib/port.c +++ b/lib/port.c @@ -147,17 +147,15 @@ next: * TTY devices. */ + if (strchr(buf, ':') == NULL) + goto next; + port.pt_names = ttys; for (cp = buf, j = 0; j < PORT_TTY; j++) { port.pt_names[j] = cp; cp = strpbrk(cp, ":,"); - if (cp == NULL) - goto next; /* line format error */ - - if (':' == *cp) { /* end of tty name list */ + if (':' == *cp) /* end of tty name list */ break; - } - if (',' == *cp) /* end of current tty name */ stpcpy(cp++, ""); } @@ -171,6 +169,9 @@ next: * The last entry in the list is a NULL pointer. */ + if (strchr(cp, ':') == NULL) + goto next; + if (':' != *cp) { port.pt_users = users; port.pt_users[0] = cp; -- 2.47.3