]> xenbits.xensource.com Git - libvirt.git/commitdiff
network: use virAsprintf when appropriate
authorEric Blake <eblake@redhat.com>
Tue, 31 Aug 2010 20:25:49 +0000 (14:25 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 1 Sep 2010 21:56:49 +0000 (15:56 -0600)
* src/conf/network_conf.c (virNetworkAllocateBridge): Avoid
limited buffer from snprintf.

src/conf/network_conf.c

index 347fc0b2e9d9a6d8a91b80934ae51d59368b9372..4c0248c5dfbaef52fd255210df02b9c735e60f90 100644 (file)
@@ -891,17 +891,14 @@ char *virNetworkAllocateBridge(const virNetworkObjListPtr nets,
         template = "virbr%d";
 
     do {
-        char try[50];
-
-        snprintf(try, sizeof(try), template, id);
-
-        if (!virNetworkBridgeInUse(nets, try, NULL)) {
-            if (!(newname = strdup(try))) {
-                virReportOOMError();
-                return NULL;
-            }
+        if (virAsprintf(&newname, template, id) < 0) {
+            virReportOOMError();
+            return NULL;
+        }
+        if (!virNetworkBridgeInUse(nets, newname, NULL)) {
             return newname;
         }
+        VIR_FREE(newname);
 
         id++;
     } while (id <= MAX_BRIDGE_ID);