]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/port.c: getportent(): Use STRSEP2ARR() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Fri, 6 Dec 2024 22:32:03 +0000 (23:32 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Sat, 7 Jun 2025 14:52:03 +0000 (16:52 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/port.c

index 26f8c2080b6ff8ba6e8743fd9501d91d1a520ed0..7e63896d3c20acc96c48de666ede16fb11da8c9c 100644 (file)
@@ -103,7 +103,8 @@ getportent(void)
        int   dtime;
        int   i, j;
        int   saveerr;
-       char  *cp, *field;
+       char  *cp;
+       char  *fields[3];
 
        static char            buf[BUFSIZ];
        static char            *ttys[PORT_TTY + 1];
@@ -147,7 +148,8 @@ next:
 
        stpsep(buf, "\n");
 
-       field = buf;
+       if (STRSEP2ARR(buf, ":", fields) == -1)
+               goto next;
 
        /*
         * Get the name of the TTY device.  It is the first colon
@@ -155,13 +157,8 @@ next:
         * leading "/dev".  The entry '*' is used to specify all
         * TTY devices.
         */
-
-       cp = strsep(&field, ":");
-       if (field == NULL)
-               goto next;
-
        port.pt_names = ttys;
-       if (STRSEP2LS(cp, ",", ttys) == -1)
+       if (STRSEP2LS(fields[0], ",", ttys) == -1)
                goto next;
 
        /*
@@ -170,13 +167,8 @@ next:
         * names.  The entry '*' is used to specify all usernames.
         * The last entry in the list is a NULL pointer.
         */
-
-       cp = strsep(&field, ":");
-       if (field == NULL)
-               goto next;
-
        port.pt_users = users;
-       if (STRSEP2LS(cp, ",", users) == -1)
+       if (STRSEP2LS(fields[1], ",", users) == -1)
                goto next;
 
        /*
@@ -192,7 +184,7 @@ next:
         * the starting time.  Days are presumed to wrap at 0000.
         */
 
-       cp = field;
+       cp = fields[2];
 
        if (streq(cp, "")) {
                port.pt_times = NULL;