提交 5da4302f 编写于 作者: E Eric Blake

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.
上级 4bcac75b
...@@ -387,8 +387,8 @@ xenapiSessionErrorHandle(virConnectPtr conn, virErrorNumber errNum, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册