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.
This commit is contained in:
Eric Blake 2010-08-18 16:57:00 -06:00
parent 4bcac75bd0
commit 5da4302f5d
2 changed files with 9 additions and 10 deletions

View 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++;
}

View 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__ */