]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/port.c: getportent(): Make sure there are at least 2 ':' in the line
authorAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 12:43:26 +0000 (14:43 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Jul 2024 12:44:02 +0000 (07:44 -0500)
Otherwise, the line is invalidly formatted, and we ignore it.

Closes: <https://github.com/shadow-maint/shadow/issues/1036>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/port.c

index f55bc724c7f69dbbe7722a33f1a1199d8df411b8..cac4ba44f0051181440b81f5e7c0c5067c5483b0 100644 (file)
@@ -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;