]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/gshadow.c: fgetsgent(): Don't use static variables
authorAlejandro Colomar <alx@kernel.org>
Mon, 22 Jul 2024 17:34:21 +0000 (19:34 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Dec 2025 01:23:18 +0000 (19:23 -0600)
BTW, getline(3) says we are responsible for free(3)ing the buffer on
error.

Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/shadow/gshadow/fgetsgent.c

index 56345d5eaa7aa2d2ca528bc774e50d30955dd068..0af9c6015fb40625d706a2a88dd21018cc4fc46e 100644 (file)
 struct sgrp *
 fgetsgent(FILE *fp)
 {
-       static size_t buflen = 0;
-       static char *buf = NULL;
+       char         *buf;
+       size_t       buflen;
+       struct sgrp  *sg;
 
        if (NULL == fp) {
                return NULL;
        }
 
+       buf = NULL;
+       buflen = 0;
        if (getline(&buf, &buflen, fp) == -1)
-               return NULL;
+               goto fail;
        if (stpsep(buf, "\n") == NULL)
-               return NULL;
+               goto fail;
+
+       sg = sgetsgent(buf);
 
-       return sgetsgent(buf);
+       free(buf);
+       return sg;
+fail:
+       free(buf);
+       return NULL;
 }
 #endif