diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2015-11-24 22:03:34 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2015-11-24 22:03:34 +0000 |
commit | a50c5c6d0278c1f74811d7af263f0a1da4572ef4 (patch) | |
tree | d0e56de3e26b5f1fd044285e3c541d6769b1bd32 /lib/libc/gen/pwcache.c | |
parent | aa7d58417b2629d9f94ae2572e2f74542c3ea214 (diff) |
Use reentrant versions of getpw{nam,uid} and getgr{nam,gid} within
libc to avoid reusing the static buffers returned by the non-reentrant
versions. Since this is inside libc we can use constants for the
buffer sizes instead of having to call sysconf().
OK guenther@ deraadt@
Diffstat (limited to 'lib/libc/gen/pwcache.c')
-rw-r--r-- | lib/libc/gen/pwcache.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c index e65112447ba..f5cfea5c20f 100644 --- a/lib/libc/gen/pwcache.c +++ b/lib/libc/gen/pwcache.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwcache.c,v 1.11 2015/11/17 17:49:09 tedu Exp $ */ +/* $OpenBSD: pwcache.c,v 1.12 2015/11/24 22:03:33 millert Exp $ */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -48,8 +48,8 @@ user_from_uid(uid_t uid, int nouser) short noname; char name[_PW_NAME_LEN + 1]; } c_uid[NLINES * NCACHE]; - static char nbuf[15]; /* 32 bits == 10 digits */ - struct passwd *pw; + char pwbuf[_PW_BUF_LEN]; + struct passwd pwstore, *pw; struct ncache *cp; unsigned int i; @@ -58,7 +58,9 @@ user_from_uid(uid_t uid, int nouser) if (!*cp->name) { fillit: cp->uid = uid; - if ((pw = getpwuid(uid)) == NULL) { + pw = NULL; + getpwuid_r(uid, &pwstore, pwbuf, sizeof(pwbuf), &pw); + if (pw == NULL) { snprintf(cp->name, sizeof(cp->name), "%u", uid); cp->noname = 1; } else { @@ -91,8 +93,8 @@ group_from_gid(gid_t gid, int nogroup) short noname; char name[_PW_NAME_LEN + 1]; } c_gid[NLINES * NCACHE]; - static char nbuf[15]; /* 32 bits == 10 digits */ - struct group *gr; + char grbuf[_PW_BUF_LEN]; + struct group grstore, *gr; struct ncache *cp; unsigned int i; @@ -101,7 +103,9 @@ group_from_gid(gid_t gid, int nogroup) if (!*cp->name) { fillit: cp->gid = gid; - if ((gr = getgrgid(gid)) == NULL) { + gr = NULL; + getgrgid_r(gid, &grstore, grbuf, sizeof(grbuf), &gr); + if (gr == NULL) { snprintf(cp->name, sizeof(cp->name), "%u", gid); cp->noname = 1; } else { |