]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util.c (two more): don't use a negative value as allocation size
authorJim Meyering <meyering@redhat.com>
Mon, 1 Feb 2010 20:45:06 +0000 (21:45 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 1 Feb 2010 21:19:15 +0000 (22:19 +0100)
* src/util/util.c (virGetUserID, virGetGroupID): 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 3c200d36800197a39dd93f452de718579dce1382..cf1290dbc9fda894b49552ea949de3f967c24a17 100644 (file)
@@ -2390,7 +2390,13 @@ int virGetUserID(virConnectPtr conn,
     char *strbuf;
     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 -1;
+    }
 
     if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
         virReportOOMError(conn);
@@ -2427,7 +2433,13 @@ int virGetGroupID(virConnectPtr conn,
     char *strbuf;
     struct group grbuf;
     struct group *gr = NULL;
-    size_t strbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+    long val = sysconf(_SC_GETGR_R_SIZE_MAX);
+    size_t strbuflen = val;
+
+    if (val < 0) {
+        virReportSystemError(conn, errno, "%s", _("sysconf failed"));
+        return -1;
+    }
 
     if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
         virReportOOMError(conn);