mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
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:
parent
4bcac75bd0
commit
5da4302f5d
@ -387,8 +387,8 @@ xenapiSessionErrorHandle(virConnectPtr conn, virErrorNumber errNum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* creates network intereface for VM */
|
/* creates network intereface for VM */
|
||||||
int
|
static int
|
||||||
createVifNetwork (virConnectPtr conn, xen_vm vm, char *device,
|
createVifNetwork (virConnectPtr conn, xen_vm vm, int device,
|
||||||
char *bridge, char *mac)
|
char *bridge, char *mac)
|
||||||
{
|
{
|
||||||
xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session;
|
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->other_config = xen_string_string_map_alloc(0);
|
||||||
vif_record->runtime_properties = 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->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);
|
xen_vif_create(session, &vif, vif_record);
|
||||||
if (!vif) {
|
if (!vif) {
|
||||||
xen_vif_free(vif);
|
xen_vif_free(vif);
|
||||||
@ -553,9 +554,11 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mac != NULL && bridge != NULL) {
|
if (mac != NULL && bridge != NULL) {
|
||||||
char device[NETWORK_DEVID_SIZE] = "\0";
|
if (createVifNetwork(conn, *vm, device_number, bridge,
|
||||||
sprintf(device, "%d", device_number);
|
mac) < 0) {
|
||||||
createVifNetwork(conn, *vm, device, bridge, mac);
|
VIR_FREE(bridge);
|
||||||
|
goto error_cleanup;
|
||||||
|
}
|
||||||
VIR_FREE(bridge);
|
VIR_FREE(bridge);
|
||||||
device_number++;
|
device_number++;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,4 @@ createVMRecordFromXml (virConnectPtr conn, virDomainDefPtr defPtr,
|
|||||||
int
|
int
|
||||||
allocStringMap (xen_string_string_map **strings, char *key, char *val);
|
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__ */
|
#endif /* __VIR_XENAPI_UTILS__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user