From: Alejandro Colomar Date: Mon, 22 Jul 2024 17:34:21 +0000 (+0200) Subject: lib/gshadow.c: fgetsgent(): Don't use static variables X-Git-Tag: 4.19.0-rc1~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e30a34a930e26c885e8c90d42bfb2f68c7e88fe;p=thirdparty%2Fshadow.git lib/gshadow.c: fgetsgent(): Don't use static variables BTW, getline(3) says we are responsible for free(3)ing the buffer on error. Reported-by: Chris Hofstaedtler Signed-off-by: Alejandro Colomar --- diff --git a/lib/shadow/gshadow/fgetsgent.c b/lib/shadow/gshadow/fgetsgent.c index 56345d5ea..0af9c6015 100644 --- a/lib/shadow/gshadow/fgetsgent.c +++ b/lib/shadow/gshadow/fgetsgent.c @@ -34,18 +34,27 @@ 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