From 5ec55b4ff0ce49032caf2373dcda52e463b81a90 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 28 Jan 2010 13:37:05 +0100 Subject: [PATCH] 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. --- src/util/util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/util.c b/src/util/util.c index 0ce5026712..701581df68 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);