summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-03-12 10:54:36 +0000
committerschwarze <schwarze@openbsd.org>2014-03-12 10:54:36 +0000
commit69bc576f1f0892e2594fd35d5cb53ca0ccaffdae (patch)
treea028508880720b20cc57ea299ddcb44a5acffa46 /lib/libc
parentUnbreak nc -6 -l. Don't retrieve and thus later set the routing table (diff)
downloadwireguard-openbsd-69bc576f1f0892e2594fd35d5cb53ca0ccaffdae.tar.xz
wireguard-openbsd-69bc576f1f0892e2594fd35d5cb53ca0ccaffdae.zip
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')
-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);
}