]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/chfn.c: Partially revert "lib/, src/: Use strsep(3) instead of its pattern"
authorAlejandro Colomar <alx@kernel.org>
Mon, 17 Feb 2025 12:23:37 +0000 (13:23 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sun, 2 Mar 2025 22:08:19 +0000 (16:08 -0600)
This partially reverts commit 16cb664865541162c504a6f5ef5ca4b38b5e0c9a.

I'll try to reintroduce this change more carefully.
For now, let's revert to a known-good state.

The problem was due to accidentally ignoring the effects of the 'break'
on the 'cp' variable.

Fixes: 16cb66486554 (2024-07-01; "lib/, src/: Use strsep(3) instead of its pattern")
Closes: <https://github.com/shadow-maint/shadow/issues/1210>
Link: <https://github.com/shadow-maint/shadow/pull/1213>
Link: <https://github.com/shadow-maint/shadow/pull/1212>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Suggested-by: Chris Hofstaedtler <zeha@debian.org>
Tested-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/chfn.c

index 4c96fba28879600dd5b6a4fe165bfab528c94841..f06cb4495a4d83b0615fc159b62da9eccf5ab0f4 100644 (file)
@@ -216,27 +216,32 @@ static void new_fields (void)
  */
 static char *copy_field (char *in, char *out, char *extra)
 {
-       while (NULL != in) {
-               char  *f;
+       char *cp = NULL;
 
-               f = strsep(&in, ",");
+       while (NULL != in) {
+               cp = strchr (in, ',');
+               if (NULL != cp) {
+                       *cp++ = '\0';
+               }
 
-               if (strchr(f, '=') == NULL)
+               if (strchr (in, '=') == NULL) {
                        break;
+               }
 
                if (NULL != extra) {
                        if (!streq(extra, "")) {
                                strcat (extra, ",");
                        }
 
-                       strcat(extra, f);
+                       strcat (extra, in);
                }
+               in = cp;
        }
        if ((NULL != in) && (NULL != out)) {
                strcpy (out, in);
        }
 
-       return in;
+       return cp;
 }
 
 /*