summaryrefslogtreecommitdiff
path: root/lib/libc/gen/getpwent.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-03-08 16:47:44 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-03-08 16:47:44 +0000
commitcb579514b65a47fde187b0771b39fbde11485721 (patch)
tree312c902eacfd7c49bdf9339578177be330827016 /lib/libc/gen/getpwent.c
parentbdebdd73cf84c7b3ad27375d36ec08e675574145 (diff)
Fix getpw{nam,uid}{,_r}() errno handling for the non-YP case.
Prevent close(2) and syslog(3) from stomping on errno; from guenther@. Set ERANGE if the buf is too small, required by POSIX; from jca@. ok millert@
Diffstat (limited to 'lib/libc/gen/getpwent.c')
-rw-r--r--lib/libc/gen/getpwent.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c
index b16626d6171..150533139e2 100644
--- a/lib/libc/gen/getpwent.c
+++ b/lib/libc/gen/getpwent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getpwent.c,v 1.49 2014/03/05 23:44:47 schwarze Exp $ */
+/* $OpenBSD: getpwent.c,v 1.50 2014/03/08 16:47:43 schwarze Exp $ */
/*
* Copyright (c) 2008 Theo de Raadt
* Copyright (c) 1988, 1993
@@ -709,7 +709,7 @@ getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t buflen,
struct passwd *pwret = NULL;
int flags = 0, *flagsp;
int my_errno = 0;
- int saved_errno;
+ int saved_errno, tmp_errno;
_THREAD_PRIVATE_MUTEX_LOCK(pw);
saved_errno = errno;
@@ -731,8 +731,10 @@ getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t buflen,
pwret = _pwhashbyname(name, buf, buflen, pw, flagsp);
if (!_pw_stayopen) {
+ tmp_errno = errno;
(void)(_pw_db->close)(_pw_db);
_pw_db = NULL;
+ errno = tmp_errno;
}
fail:
if (pwretp)
@@ -762,7 +764,7 @@ getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t buflen,
struct passwd *pwret = NULL;
int flags = 0, *flagsp;
int my_errno = 0;
- int saved_errno;
+ int saved_errno, tmp_errno;
_THREAD_PRIVATE_MUTEX_LOCK(pw);
saved_errno = errno;
@@ -784,8 +786,10 @@ getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t buflen,
pwret = _pwhashbyuid(uid, buf, buflen, pw, flagsp);
if (!_pw_stayopen) {
+ tmp_errno = errno;
(void)(_pw_db->close)(_pw_db);
_pw_db = NULL;
+ errno = tmp_errno;
}
fail:
if (pwretp)
@@ -867,9 +871,12 @@ __initdb(void)
errno = saved_errno;
return (1);
}
- if (!warned)
+ if (!warned) {
+ saved_errno = errno;
syslog(LOG_ERR, "%s: %m", _PATH_MP_DB);
- warned = 1;
+ errno = saved_errno;
+ warned = 1;
+ }
return (0);
}
@@ -883,8 +890,10 @@ __hashpw(DBT *key, char *buf, size_t buflen, struct passwd *pw,
if ((_pw_db->get)(_pw_db, key, &data, 0))
return (0);
p = (char *)data.data;
- if (data.size > buflen)
+ if (data.size > buflen) {
+ errno = ERANGE;
return (0);
+ }
t = buf;
#define EXPAND(e) e = t; while ((*t++ = *p++));