From: Alejandro Colomar Date: Tue, 2 Jul 2024 16:57:44 +0000 (+0200) Subject: lib/port.c: getportent(): Use strsep(3) instead of its pattern X-Git-Tag: 4.17.0-rc1~133 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cee79c215a7b15575d721a2520dc5ebe4dd55c9d;p=thirdparty%2Fshadow.git lib/port.c: getportent(): Use strsep(3) instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/port.c b/lib/port.c index 23b9a1b62..efb85a72f 100644 --- a/lib/port.c +++ b/lib/port.c @@ -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;