]> xenbits.xensource.com Git - libvirt.git/commitdiff
util.c (virGetUserEnt): don't use a negative value as allocation size
authorJim Meyering <meyering@redhat.com>
Thu, 28 Jan 2010 12:37:05 +0000 (13:37 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 29 Jan 2010 20:43:02 +0000 (21:43 +0100)
* 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

index 0ce5026712d778dddec7d5fbee562d1649963129..701581df68c55c0fe025ebad185d02c7898037d5 100644 (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);