summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-03-12 10:54:37 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-03-12 10:54:37 +0000
commit4cef5a52c78e6c81bbd9dc50a630f8cdd0b2a790 (patch)
tree9698921748dd052d45fbe8b85a53926a8a3a6c11 /lib/libc/gen
parent7774084009eb746d3175c4d1c06eb4b8db52dddb (diff)
Make sure that setgrent(), endgrent(), and endpwent() do not clobber
errno; they might do so on open() and close() failures, but by POSIX, they are not supposed to fail. Note that ignoring failures inside setgrent() does not matter, the following getgrent() is bound to fail the same way again, anyway. If you insist on detecting open() failure, use setgroupent(), even though that is less portable. While here, remove two pointless (void) casts. ok millert@ jca@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/getgrent.c14
-rw-r--r--lib/libc/gen/getpwent.c6
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index 01ae4ffad60..e15d14e3b23 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getgrent.c,v 1.39 2014/03/05 23:44:47 schwarze Exp $ */
+/* $OpenBSD: getgrent.c,v 1.40 2014/03/12 10:54:36 schwarze Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -213,7 +213,11 @@ start_gr(void)
void
setgrent(void)
{
- (void) setgroupent(0);
+ int saved_errno;
+
+ saved_errno = errno;
+ setgroupent(0);
+ errno = saved_errno;
}
int
@@ -236,8 +240,11 @@ static
void
endgrent_basic(void)
{
+ int saved_errno;
+
if (_gr_fp) {
- (void)fclose(_gr_fp);
+ saved_errno = errno;
+ fclose(_gr_fp);
_gr_fp = NULL;
#ifdef YP
__ypmode = 0;
@@ -248,6 +255,7 @@ endgrent_basic(void)
__ypexclude_free(&__ypexhead);
__ypexhead = NULL;
#endif
+ errno = saved_errno;
}
}
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index 1ac071ffc18..732cf884997 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getpwent.c,v 1.51 2014/03/12 09:58:23 schwarze Exp $ */
+/* $OpenBSD: getpwent.c,v 1.52 2014/03/12 10:54:36 schwarze Exp $ */
/*
* Copyright (c) 2008 Theo de Raadt
* Copyright (c) 1988, 1993
@@ -847,7 +847,10 @@ setpwent(void)
void
endpwent(void)
{
+ int saved_errno;
+
_THREAD_PRIVATE_MUTEX_LOCK(pw);
+ saved_errno = errno;
_pw_keynum = 0;
if (_pw_db) {
(void)(_pw_db->close)(_pw_db);
@@ -861,6 +864,7 @@ endpwent(void)
__ypexclude_free(&__ypexhead);
__ypproto = NULL;
#endif
+ errno = saved_errno;
_THREAD_PRIVATE_MUTEX_UNLOCK(pw);
}