Don't let endgrent clobber errno, no matter how improbable.
authorJim Meyering <jim@meyering.net>
Thu, 5 Jul 2007 08:06:33 +0000 (08:06 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 5 Jul 2007 08:06:33 +0000 (08:06 +0000)
* lib/getugroups.c (getugroups): Save and restore errno around
endgrent call.

ChangeLog
lib/getugroups.c

index b2bd707fb495180b3ed4fad505c2471708983f2a..ec8b45fd1a3cdb06856ae222a788937c801fd695 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-07-05  Jim Meyering  <jim@meyering.net>
 
+       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.
 
index d63a6072e4861227f838f4d8aa60dd7eb1a71f6f..43d0650a0f5ee086b157c3aa46b3cf978495cf52 100644 (file)
@@ -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;
 }