[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 07/10] xenapi: avoid sprintf



* 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.
---

I couldn't find any other uses of createVifNetwork, so changing
its prototype and marking it static seemed best.

 src/xenapi/xenapi_utils.c |   15 +++++++++------
 src/xenapi/xenapi_utils.h |    4 ----
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 4eb17fa..23d3fef 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -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++;
             }
diff --git a/src/xenapi/xenapi_utils.h b/src/xenapi/xenapi_utils.h
index c062a1e..2140105 100644
--- a/src/xenapi/xenapi_utils.h
+++ b/src/xenapi/xenapi_utils.h
@@ -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__ */
-- 
1.7.2.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]