# HG changeset patch
# User john.levon(a)sun.com
# Date 1233280613 28800
# Node ID 59c231ad7e158acead0c236c3a52f60718b84605
# Parent b203988038c14f1160cbd250a48eda40d4613eca
Fix getpwuid_r() usage
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/util.c b/src/util.c
--- a/src/util.c
+++ b/src/util.c
@@ -1477,7 +1477,7 @@ char *virGetUserDirectory(virConnectPtr
char *strbuf;
char *ret;
struct passwd pwbuf;
- struct passwd *pw;
+ struct passwd *pw = NULL;
size_t strbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
@@ -1485,7 +1485,14 @@ char *virGetUserDirectory(virConnectPtr
return NULL;
}
- if (getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw) != 0) {
+ /*
+ * From the manpage (terrifying but true):
+ *
+ * ERRORS
+ * 0 or ENOENT or ESRCH or EBADF or EPERM or ...
+ * The given name or uid was not found.
+ */
+ if (getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw) != 0 || pw == NULL)
virReportSystemError(conn, errno,
_("Failed to find user record for uid
'%d'"),
uid);