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.
This commit is contained in:
Jim Meyering 2010-01-28 13:37:05 +01:00
parent 3bd3d6b0bf
commit 5ec55b4ff0

View File

@ -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);