From 5e30a34a930e26c885e8c90d42bfb2f68c7e88fe Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 22 Jul 2024 19:34:21 +0200 Subject: [PATCH] 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 --- lib/shadow/gshadow/fgetsgent.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 -- 2.47.3