]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/chfn.c: Write an empty string if there's nothing in the GECOS field
authorAlejandro Colomar <alx@kernel.org>
Fri, 18 Jul 2025 22:18:30 +0000 (00:18 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 9 Aug 2025 23:00:36 +0000 (18:00 -0500)
Otherwise, the buffer would contain garbage.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/chfn.c

index 6834366c0be2e2910e1e3ba77b2893828122dccc..4c7f5c55914bb46cc0e19e12e194881cc2ab0f1b 100644 (file)
@@ -480,23 +480,23 @@ static void get_old_fields (const char *gecos)
 
        f = strsep(&p, ",");
        if (!fflg)
-               strcpy(fullnm, f);
+               strcpy(fullnm, f ?: "");
 
        f = strsep(&p, ",");
-       if (!rflg && f != NULL)
-               strcpy(roomno, f);
+       if (!rflg)
+               strcpy(roomno, f ?: "");
 
        f = strsep(&p, ",");
-       if (!wflg && f != NULL)
-               strcpy(workph, f);
+       if (!wflg)
+               strcpy(workph, f ?: "");
 
        f = strsep(&p, ",");
-       if (!hflg && f != NULL)
-               strcpy(homeph, f);
+       if (!hflg)
+               strcpy(homeph, f ?: "");
 
        /* Anything left over is "slop".  */
-       if (!oflg && p != NULL)
-               strcpy(slop, p);
+       if (!oflg)
+               strcpy(slop, p ?: "");
 }
 
 /*