summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-07-18 10:09:45 +0200
committerStef Walter <stef@thewalter.net>2013-07-18 13:04:37 +0200
commita1a398ae150cee642efaa03f28e8457c75185d55 (patch)
treebc18846959bed40c30431f0f9327926f86e37421
parentb03be8429847451ddf25508b3dc3c520e96a2cc3 (diff)
Use getpwuid_r() instead of the non-thread-sofe getpwuid()
-rw-r--r--common/path.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/common/path.c b/common/path.c
index f7bd2b9..3c714d5 100644
--- a/common/path.c
+++ b/common/path.c
@@ -131,11 +131,18 @@ expand_homedir (const char *remainder)
} else {
#ifdef OS_UNIX
+ char buf[1024];
+ struct passwd pws;
struct passwd *pwd;
int error = 0;
+ int ret;
- pwd = getpwuid (getuid ());
- if (!pwd) {
+ ret = getpwuid_r (getuid (), &pws, buf, sizeof (buf), &pwd);
+ if (ret == 0 && !pwd) {
+ ret = -1;
+ errno = ESRCH;
+ }
+ if (ret < 0) {
error = errno;
p11_message_err (errno, "couldn't lookup home directory for user %d", getuid ());
errno = error;