diff options
author | 2010-01-28 13:37:05 +0100 | |
---|---|---|
committer | 2010-01-29 21:43:02 +0100 | |
commit | 5ec55b4ff0ce49032caf2373dcda52e463b81a90 (patch) | |
tree | b1e6807fdd6d2658838e2086eb2dffbe1678b68c | |
parent | Support Xen 4.0 sysctl version 7 (diff) | |
download | libvirt-5ec55b4ff0ce49032caf2373dcda52e463b81a90.tar.gz libvirt-5ec55b4ff0ce49032caf2373dcda52e463b81a90.tar.bz2 libvirt-5ec55b4ff0ce49032caf2373dcda52e463b81a90.zip |
util.c (virGetUserEnt): don't use a negative value as allocation size
* src/util/util.c (virGetUserEnt): In the unlikely event that
sysconf(_SC_GETPW_R_SIZE_MAX) fails, don't use -1 as the size in
the subsequent allocation.
-rw-r--r-- | src/util/util.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/util/util.c b/src/util/util.c index 0ce502671..701581df6 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -2317,7 +2317,13 @@ static char *virGetUserEnt(virConnectPtr conn, char *ret; struct passwd pwbuf; struct passwd *pw = NULL; - size_t strbuflen = sysconf(_SC_GETPW_R_SIZE_MAX); + long val = sysconf(_SC_GETPW_R_SIZE_MAX); + size_t strbuflen = val; + + if (val < 0) { + virReportSystemError(conn, errno, "%s", _("sysconf failed")); + return NULL; + } if (VIR_ALLOC_N(strbuf, strbuflen) < 0) { virReportOOMError(conn); |