From 72c48440c1f459e2659270598b771c69e9c08994 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 5 Jul 2007 08:06:33 +0000 Subject: [PATCH] Don't let endgrent clobber errno, no matter how improbable. * lib/getugroups.c (getugroups): Save and restore errno around endgrent call. --- ChangeLog | 4 ++++ lib/getugroups.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b2bd707fb4..ec8b45fd1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-07-05 Jim Meyering + Don't let endgrent clobber errno, no matter how improbable. + * lib/getugroups.c (getugroups): Save and restore errno around + endgrent call. + Close the group DB even when failing with 2^31 or more members. * lib/getugroups.c (getugroups): Don't return without calling endgrent. diff --git a/lib/getugroups.c b/lib/getugroups.c index d63a6072e4..43d0650a0f 100644 --- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -99,7 +99,11 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char const *username, } done: - endgrent (); + { + int saved_errno = errno; + endgrent (); + errno = saved_errno; + } return count; } -- 2.30.2