]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/port.c: getportent(): Use strsep(3) instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 16:57:44 +0000 (18:57 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Jul 2024 12:44:02 +0000 (07:44 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/port.c

index 23b9a1b625723505e4e459b3b96a551ac4680d6b..efb85a72f7094948e91ed19277e2bb31435dd65c 100644 (file)
@@ -100,7 +100,7 @@ getportent(void)
        int   dtime;
        int   i, j;
        int   saveerr;
-       char  *cp;
+       char  *cp, *field;
 
        static char            buf[BUFSIZ];
        static char            *ttys[PORT_TTY + 1];
@@ -144,6 +144,8 @@ next:
 
        stpcpy(strchrnul(buf, '\n'), "");
 
+       field = buf;
+
        /*
         * Get the name of the TTY device.  It is the first colon
         * separated field, and is the name of the TTY with no
@@ -151,24 +153,20 @@ next:
         * TTY devices.
         */
 
-       if (strchr(buf, ':') == NULL)
+       cp = strsep(&field, ":");
+       if (field == 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)
+       for (j = 0; j < PORT_TTY; j++) {
+               port.pt_names[j] = strsep(&cp, ",");
+               if (cp == NULL)
                        break;
-               if (',' == *cp)
-                       stpcpy(cp++, "");
        }
        port.pt_names[j] = NULL;
-       if (':' != *cp)
+       if (cp != NULL)
                goto next;
 
-       stpcpy(cp++, "");
-
        /*
         * Get the list of user names.  It is the second colon
         * separated field, and is a comma separated list of user
@@ -176,24 +174,20 @@ next:
         * The last entry in the list is a NULL pointer.
         */
 
-       if (strchr(cp, ':') == NULL)
+       cp = strsep(&field, ":");
+       if (field == NULL)
                goto next;
 
        port.pt_users = users;
        for (j = 0; j < PORT_IDS; j++) {
-               port.pt_users[j] = cp;
-               cp = strpbrk(cp, ":,");
-               if (':' == *cp)
+               port.pt_users[j] = strsep(&cp, ",");
+               if (cp == NULL)
                        break;
-               if (',' == *cp)
-                       stpcpy(cp++, "");
        }
        port.pt_users[j] = NULL;
-       if (':' != *cp)
+       if (cp != NULL)
                goto next;
 
-       stpcpy(cp++, "");
-
        /*
         * Get the list of valid times.  The times field is the third
         * colon separated field and is a list of days of the week and
@@ -207,6 +201,8 @@ next:
         * the starting time.  Days are presumed to wrap at 0000.
         */
 
+       cp = field;
+
        if ('\0' == *cp) {
                port.pt_times = 0;
                return &port;