]> xenbits.xensource.com Git - libvirt.git/commitdiff
xenapi: avoid sprintf
authorEric Blake <eblake@redhat.com>
Wed, 18 Aug 2010 22:57:00 +0000 (16:57 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 19 Aug 2010 22:18:11 +0000 (16:18 -0600)
* src/xenapi/xenapi_utils.h (createVifNetwork): Delete prototype.
* src/xenapi/xenapi_utils.c (createVifNetwork): Change signature,
and use virAsprintf.  Detect allocation failure.
(createVMRecordFromXml): Adjust caller.

src/xenapi/xenapi_utils.c
src/xenapi/xenapi_utils.h

index 4eb17fab5eec219889ba0c04b0052c633049a73b..23d3fef8ef75624093c011045c3f6540156ddf8a 100644 (file)
@@ -387,8 +387,8 @@ xenapiSessionErrorHandle(virConnectPtr conn, virErrorNumber errNum,
 }
 
 /* creates network intereface for VM */
-int
-createVifNetwork (virConnectPtr conn, xen_vm vm, char *device,
+static int
+createVifNetwork (virConnectPtr conn, xen_vm vm, int device,
                   char *bridge, char *mac)
 {
     xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session;
@@ -432,7 +432,8 @@ createVifNetwork (virConnectPtr conn, xen_vm vm, char *device,
         vif_record->other_config = xen_string_string_map_alloc(0);
         vif_record->runtime_properties = xen_string_string_map_alloc(0);
         vif_record->qos_algorithm_params = xen_string_string_map_alloc(0);
-        vif_record->device = strdup(device);
+        if (virAsprintf(&vif_record->device, "%d", device) < 0)
+            return -1;
         xen_vif_create(session, &vif, vif_record);
         if (!vif) {
             xen_vif_free(vif);
@@ -553,9 +554,11 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr def,
                 }
             }
             if (mac != NULL && bridge != NULL) {
-                char device[NETWORK_DEVID_SIZE] = "\0";
-                sprintf(device, "%d", device_number);
-                createVifNetwork(conn, *vm, device, bridge, mac);
+                if (createVifNetwork(conn, *vm, device_number, bridge,
+                                     mac) < 0) {
+                    VIR_FREE(bridge);
+                    goto error_cleanup;
+                }
                 VIR_FREE(bridge);
                 device_number++;
             }
index c062a1e27b1918016e219efb76b5ad3762a9b530..214010534f0c481a2d52fd7ab4ae757efa0f5744 100644 (file)
@@ -78,8 +78,4 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr defPtr,
 int
 allocStringMap (xen_string_string_map **strings, char *key, char *val);
 
-int
-createVifNetwork(virConnectPtr conn, xen_vm vm, char *device,
-                 char *bridge, char *mac);
-
 #endif /* __VIR_XENAPI_UTILS__ */