From eb77fbdcec0b6f4bb396c0a8ce20f17687d1c7fa Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Sat, 7 Feb 2015 19:51:34 +0000 Subject: [PATCH] Protect uninitialized scalar variable from being accessed In a couple of cases a variable "stayopen" can be checked unitialized. This is of no danger as the complementary condition is false but prevent the access by switching the checks. CID: 1018729 CID: 1018732 --- lib/libc/gen/getgrent.c | 2 +- lib/libc/gen/getpwent.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index f9480c3a22f..caa5ad5ef2e 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -896,7 +896,7 @@ files_group(void *retval, void *mdata, va_list ap) break; pos = ftello(st->fp); } - if (!stayopen && st->fp != NULL) { + if (st->fp != NULL && !stayopen) { fclose(st->fp); st->fp = NULL; } diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index f729cdf1d41..7cf7f47941e 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -921,7 +921,7 @@ files_passwd(void *retval, void *mdata, va_list ap) errnop); } while (how == nss_lt_all && !(rv & NS_TERMINATE)); fin: - if (!stayopen && st->db != NULL) { + if (st->db != NULL && !stayopen) { (void)st->db->close(st->db); st->db = NULL; } -- 2.45.2