remote: check & report OOM in make_nonnull_XXX methods

The make_nonnull_XXX methods can all fail due to OOM but this was being
silently ignored and thus also not checked by callers. Make the methods
propagate errors and use ATTRIBUTE_RETURN_CHECK to force callers to deal
with it.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-12-10 18:48:47 +00:00
parent 600462834f
commit dc54b3ecc9
3 changed files with 315 additions and 106 deletions

View File

@ -113,11 +113,13 @@ get_nonnull_server(virNetDaemonPtr dmn, admin_nonnull_server srv)
return virNetDaemonGetServer(dmn, srv.name);
}
static void
static int ATTRIBUTE_RETURN_CHECK
make_nonnull_server(admin_nonnull_server *srv_dst,
virNetServerPtr srv_src)
{
ignore_value(VIR_STRDUP_QUIET(srv_dst->name, virNetServerGetName(srv_src)));
if (VIR_STRDUP(srv_dst->name, virNetServerGetName(srv_src)) < 0)
return -1;
return 0;
}
static virNetServerClientPtr
@ -126,13 +128,14 @@ get_nonnull_client(virNetServerPtr srv, admin_nonnull_client clnt)
return virNetServerGetClient(srv, clnt.id);
}
static void
static int
make_nonnull_client(admin_nonnull_client *clt_dst,
virNetServerClientPtr clt_src)
{
clt_dst->id = virNetServerClientGetID(clt_src);
clt_dst->timestamp = virNetServerClientGetTimestamp(clt_src);
clt_dst->transport = virNetServerClientGetTransport(clt_src);
return 0;
}
/* Functions */

View File

@ -91,16 +91,16 @@ static virNWFilterPtr get_nonnull_nwfilter(virConnectPtr conn, remote_nonnull_nw
static virNWFilterBindingPtr get_nonnull_nwfilter_binding(virConnectPtr conn, remote_nonnull_nwfilter_binding binding);
static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr dom, remote_nonnull_domain_snapshot snapshot);
static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote_nonnull_node_device dev);
static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src);
static void make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src);
static void make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src);
static void make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src);
static void make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src);
static void make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src);
static void make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecretPtr secret_src);
static void make_nonnull_nwfilter(remote_nonnull_nwfilter *net_dst, virNWFilterPtr nwfilter_src);
static void make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding *binding_dst, virNWFilterBindingPtr binding_src);
static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src);
static int make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecretPtr secret_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_nwfilter(remote_nonnull_nwfilter *net_dst, virNWFilterPtr nwfilter_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding *binding_dst, virNWFilterBindingPtr binding_src) ATTRIBUTE_RETURN_CHECK;
static int make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src) ATTRIBUTE_RETURN_CHECK;
static int
remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
@ -313,7 +313,8 @@ remoteRelayDomainEventLifecycle(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.event = event;
data.detail = detail;
@ -333,6 +334,11 @@ remoteRelayDomainEventLifecycle(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_lifecycle_msg,
&data);
return -1;
}
static int
@ -352,7 +358,8 @@ remoteRelayDomainEventReboot(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -368,6 +375,11 @@ remoteRelayDomainEventReboot(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_reboot_msg,
&data);
return -1;
}
@ -390,7 +402,8 @@ remoteRelayDomainEventRTCChange(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.offset = offset;
if (callback->legacy) {
@ -407,6 +420,11 @@ remoteRelayDomainEventRTCChange(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_rtc_change_msg,
&data);
return -1;
}
@ -428,7 +446,8 @@ remoteRelayDomainEventWatchdog(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.action = action;
if (callback->legacy) {
@ -445,6 +464,11 @@ remoteRelayDomainEventWatchdog(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_watchdog_msg,
&data);
return -1;
}
@ -472,7 +496,8 @@ remoteRelayDomainEventIOError(virConnectPtr conn,
if (VIR_STRDUP(data.srcPath, srcPath) < 0 ||
VIR_STRDUP(data.devAlias, devAlias) < 0)
goto error;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.action = action;
if (callback->legacy) {
@ -490,8 +515,8 @@ remoteRelayDomainEventIOError(virConnectPtr conn,
return 0;
error:
VIR_FREE(data.srcPath);
VIR_FREE(data.devAlias);
xdr_free((xdrproc_t)xdr_remote_domain_event_io_error_msg,
&data);
return -1;
}
@ -524,7 +549,8 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn,
goto error;
data.action = action;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -542,9 +568,8 @@ remoteRelayDomainEventIOErrorReason(virConnectPtr conn,
return 0;
error:
VIR_FREE(data.srcPath);
VIR_FREE(data.devAlias);
VIR_FREE(data.reason);
xdr_free((xdrproc_t)xdr_remote_domain_event_io_error_reason_msg,
&data);
return -1;
}
@ -598,7 +623,8 @@ remoteRelayDomainEventGraphics(virConnectPtr conn,
VIR_STRDUP(data.subject.subject_val[i].name, subject->identities[i].name) < 0)
goto error;
}
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -616,18 +642,8 @@ remoteRelayDomainEventGraphics(virConnectPtr conn,
return 0;
error:
VIR_FREE(data.authScheme);
VIR_FREE(data.local.node);
VIR_FREE(data.local.service);
VIR_FREE(data.remote.node);
VIR_FREE(data.remote.service);
if (data.subject.subject_val != NULL) {
for (i = 0; i < data.subject.subject_len; i++) {
VIR_FREE(data.subject.subject_val[i].type);
VIR_FREE(data.subject.subject_val[i].name);
}
VIR_FREE(data.subject.subject_val);
}
xdr_free((xdrproc_t)xdr_remote_domain_event_graphics_msg,
&data);
return -1;
}
@ -655,7 +671,8 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn,
return -1;
data.type = type;
data.status = status;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -671,6 +688,11 @@ remoteRelayDomainEventBlockJob(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_block_job_msg,
&data);
return -1;
}
@ -691,7 +713,8 @@ remoteRelayDomainEventControlError(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -707,6 +730,11 @@ remoteRelayDomainEventControlError(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_control_error_msg,
&data);
return -1;
}
@ -749,7 +777,8 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn,
goto error;
data.reason = reason;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -767,8 +796,8 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn,
return 0;
error:
VIR_FREE(oldSrcPath_p);
VIR_FREE(newSrcPath_p);
xdr_free((xdrproc_t)xdr_remote_domain_event_disk_change_msg,
&data);
return -1;
}
@ -797,7 +826,8 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn,
return -1;
data.reason = reason;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -813,6 +843,11 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_tray_change_msg,
&data);
return -1;
}
static int
@ -833,7 +868,8 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -849,6 +885,11 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_pmwakeup_msg,
&data);
return -1;
}
static int
@ -869,7 +910,8 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -885,6 +927,11 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_pmsuspend_msg,
&data);
return -1;
}
static int
@ -905,7 +952,8 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.actual = actual;
if (callback->legacy) {
@ -922,6 +970,11 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_balloon_change_msg,
&data);
return -1;
}
@ -943,7 +996,8 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -959,6 +1013,11 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_pmsuspend_disk_msg,
&data);
return -1;
}
static int
@ -983,7 +1042,8 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn,
if (VIR_STRDUP(data.devAlias, devAlias) < 0)
return -1;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (callback->legacy) {
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1001,6 +1061,11 @@ remoteRelayDomainEventDeviceRemoved(virConnectPtr conn,
}
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_device_removed_msg,
&data);
return -1;
}
@ -1029,13 +1094,19 @@ remoteRelayDomainEventBlockJob2(virConnectPtr conn,
return -1;
data.type = type;
data.status = status;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB_2,
(xdrproc_t)xdr_remote_domain_event_block_job_2_msg, &data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_block_job_2_msg,
&data);
return -1;
}
@ -1059,7 +1130,8 @@ remoteRelayDomainEventTunable(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
data.callbackID = callback->callbackID;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (virTypedParamsSerialize(params, nparams,
(virTypedParameterRemotePtr *) &data.params.params_val,
@ -1075,6 +1147,11 @@ remoteRelayDomainEventTunable(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_tunable_msg,
&data);
return -1;
}
@ -1099,7 +1176,8 @@ remoteRelayDomainEventAgentLifecycle(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
data.callbackID = callback->callbackID;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.state = state;
data.reason = reason;
@ -1110,6 +1188,11 @@ remoteRelayDomainEventAgentLifecycle(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_agent_lifecycle_msg,
&data);
return -1;
}
@ -1135,7 +1218,8 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn,
if (VIR_STRDUP(data.devAlias, devAlias) < 0)
return -1;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.callbackID = callback->callbackID;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1144,6 +1228,11 @@ remoteRelayDomainEventDeviceAdded(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_device_added_msg,
&data);
return -1;
}
@ -1167,7 +1256,8 @@ remoteRelayDomainEventMigrationIteration(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
data.callbackID = callback->callbackID;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.iteration = iteration;
@ -1177,6 +1267,11 @@ remoteRelayDomainEventMigrationIteration(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_migration_iteration_msg,
&data);
return -1;
}
@ -1201,7 +1296,8 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
data.callbackID = callback->callbackID;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
if (virTypedParamsSerialize(params, nparams,
(virTypedParameterRemotePtr *) &data.params.params_val,
@ -1216,6 +1312,11 @@ remoteRelayDomainEventJobCompleted(virConnectPtr conn,
(xdrproc_t)xdr_remote_domain_event_callback_job_completed_msg,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_job_completed_msg,
&data);
return -1;
}
@ -1241,7 +1342,8 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectPtr conn,
if (VIR_STRDUP(data.devAlias, devAlias) < 0)
return -1;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.callbackID = callback->callbackID;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1250,6 +1352,11 @@ remoteRelayDomainEventDeviceRemovalFailed(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_device_removal_failed_msg,
&data);
return -1;
}
@ -1285,7 +1392,8 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn,
data.nsuri = nsurip;
}
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
data.callbackID = callback->callbackID;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1294,6 +1402,11 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_domain_event_callback_metadata_change_msg,
&data);
return -1;
}
@ -1329,15 +1442,18 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr conn,
}
data.threshold = threshold;
data.excess = excess;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
REMOTE_PROC_DOMAIN_EVENT_BLOCK_THRESHOLD,
(xdrproc_t)xdr_remote_domain_event_block_threshold_msg, &data);
return 0;
error:
VIR_FREE(data.dev);
xdr_free((xdrproc_t)xdr_remote_domain_event_block_threshold_msg,
&data);
return -1;
}
@ -1391,7 +1507,8 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_network(&data.net, net);
if (make_nonnull_network(&data.net, net) < 0)
goto error;
data.callbackID = callback->callbackID;
data.event = event;
data.detail = detail;
@ -1401,6 +1518,11 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn,
(xdrproc_t)xdr_remote_network_event_lifecycle_msg, &data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_network_event_lifecycle_msg,
&data);
return -1;
}
static virConnectNetworkEventGenericCallback networkEventCallbacks[] = {
@ -1428,7 +1550,8 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_storage_pool(&data.pool, pool);
if (make_nonnull_storage_pool(&data.pool, pool) < 0)
goto error;
data.callbackID = callback->callbackID;
data.event = event;
data.detail = detail;
@ -1439,6 +1562,11 @@ remoteRelayStoragePoolEventLifecycle(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_storage_pool_event_lifecycle_msg,
&data);
return -1;
}
static int
@ -1458,7 +1586,8 @@ remoteRelayStoragePoolEventRefresh(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_storage_pool(&data.pool, pool);
if (make_nonnull_storage_pool(&data.pool, pool) < 0)
goto error;
data.callbackID = callback->callbackID;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1467,6 +1596,11 @@ remoteRelayStoragePoolEventRefresh(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_storage_pool_event_refresh_msg,
&data);
return -1;
}
static virConnectStoragePoolEventGenericCallback storageEventCallbacks[] = {
@ -1495,7 +1629,8 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_node_device(&data.dev, dev);
if (make_nonnull_node_device(&data.dev, dev) < 0)
goto error;
data.callbackID = callback->callbackID;
data.event = event;
data.detail = detail;
@ -1506,6 +1641,11 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_node_device_event_lifecycle_msg,
&data);
return -1;
}
static int
@ -1525,7 +1665,8 @@ remoteRelayNodeDeviceEventUpdate(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_node_device(&data.dev, dev);
if (make_nonnull_node_device(&data.dev, dev) < 0)
goto error;
data.callbackID = callback->callbackID;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1534,6 +1675,11 @@ remoteRelayNodeDeviceEventUpdate(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_node_device_event_update_msg,
&data);
return -1;
}
static virConnectNodeDeviceEventGenericCallback nodeDeviceEventCallbacks[] = {
@ -1562,7 +1708,8 @@ remoteRelaySecretEventLifecycle(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_secret(&data.secret, secret);
if (make_nonnull_secret(&data.secret, secret) < 0)
goto error;
data.callbackID = callback->callbackID;
data.event = event;
data.detail = detail;
@ -1573,6 +1720,11 @@ remoteRelaySecretEventLifecycle(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_secret_event_lifecycle_msg,
&data);
return -1;
}
static int
@ -1592,7 +1744,8 @@ remoteRelaySecretEventValueChanged(virConnectPtr conn,
/* build return data */
memset(&data, 0, sizeof(data));
make_nonnull_secret(&data.secret, secret);
if (make_nonnull_secret(&data.secret, secret) < 0)
goto error;
data.callbackID = callback->callbackID;
remoteDispatchObjectEventSend(callback->client, remoteProgram,
@ -1601,6 +1754,11 @@ remoteRelaySecretEventValueChanged(virConnectPtr conn,
&data);
return 0;
error:
xdr_free((xdrproc_t)xdr_remote_secret_event_value_changed_msg,
&data);
return -1;
}
static virConnectSecretEventGenericCallback secretEventCallbacks[] = {
@ -1643,7 +1801,8 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn,
VIR_STRDUP(*details_p, details) < 0))
goto error;
data.details = details_p;
make_nonnull_domain(&data.dom, dom);
if (make_nonnull_domain(&data.dom, dom) < 0)
goto error;
remoteDispatchObjectEventSend(callback->client, qemuProgram,
QEMU_PROC_DOMAIN_MONITOR_EVENT,
@ -1652,8 +1811,9 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn,
return;
error:
VIR_FREE(data.event);
VIR_FREE(details_p);
xdr_free((xdrproc_t)xdr_qemu_domain_monitor_event_msg,
&data);
return;
}
static
@ -4647,7 +4807,8 @@ remoteDispatchDomainMigrateFinish3(virNetServerPtr server ATTRIBUTE_UNUSED,
args->cancelled)))
goto cleanup;
make_nonnull_domain(&ret->dom, dom);
if (make_nonnull_domain(&ret->dom, dom) < 0)
goto cleanup;
/* remoteDispatchClientRequest will free cookie
*/
@ -5583,7 +5744,8 @@ remoteDispatchDomainMigrateFinish3Params(virNetServerPtr server ATTRIBUTE_UNUSED
if (!dom)
goto cleanup;
make_nonnull_domain(&ret->dom, dom);
if (make_nonnull_domain(&ret->dom, dom) < 0)
goto cleanup;
ret->cookie_out.cookie_out_len = cookieoutlen;
ret->cookie_out.cookie_out_val = cookieout;
@ -5738,7 +5900,9 @@ remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server ATTRIBUTE_UNUSED,
args->flags)) == NULL)
goto cleanup;
make_nonnull_domain(&ret->dom, dom);
if (make_nonnull_domain(&ret->dom, dom) < 0)
goto cleanup;
rv = 0;
cleanup:
@ -5788,7 +5952,9 @@ static int remoteDispatchDomainCreateWithFiles(virNetServerPtr server ATTRIBUTE_
args->flags) < 0)
goto cleanup;
make_nonnull_domain(&ret->dom, dom);
if (make_nonnull_domain(&ret->dom, dom) < 0)
goto cleanup;
rv = 0;
cleanup:
@ -6684,7 +6850,8 @@ remoteDispatchConnectGetAllDomainStats(virNetServerPtr server ATTRIBUTE_UNUSED,
for (i = 0; i < nrecords; i++) {
remote_domain_stats_record *dst = ret->retStats.retStats_val + i;
make_nonnull_domain(&dst->dom, retStats[i]->dom);
if (make_nonnull_domain(&dst->dom, retStats[i]->dom) < 0)
goto cleanup;
if (virTypedParamsSerialize(retStats[i]->params,
retStats[i]->nparams,
@ -7104,77 +7271,113 @@ get_nonnull_node_device(virConnectPtr conn, remote_nonnull_node_device dev)
}
/* Make remote_nonnull_domain and remote_nonnull_network. */
static void
static int
make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src)
{
dom_dst->id = dom_src->id;
ignore_value(VIR_STRDUP_QUIET(dom_dst->name, dom_src->name));
if (VIR_STRDUP(dom_dst->name, dom_src->name) < 0)
return -1;
memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN);
return 0;
}
static void
static int
make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src)
{
ignore_value(VIR_STRDUP_QUIET(net_dst->name, net_src->name));
if (VIR_STRDUP(net_dst->name, net_src->name) < 0)
return -1;
memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN);
return 0;
}
static void
static int
make_nonnull_interface(remote_nonnull_interface *interface_dst,
virInterfacePtr interface_src)
{
ignore_value(VIR_STRDUP_QUIET(interface_dst->name, interface_src->name));
ignore_value(VIR_STRDUP_QUIET(interface_dst->mac, interface_src->mac));
if (VIR_STRDUP(interface_dst->name, interface_src->name) < 0)
return -1;
if (VIR_STRDUP(interface_dst->mac, interface_src->mac) < 0) {
VIR_FREE(interface_dst->name);
return -1;
}
return 0;
}
static void
static int
make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src)
{
ignore_value(VIR_STRDUP_QUIET(pool_dst->name, pool_src->name));
if (VIR_STRDUP(pool_dst->name, pool_src->name) < 0)
return -1;
memcpy(pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN);
return 0;
}
static void
static int
make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src)
{
ignore_value(VIR_STRDUP_QUIET(vol_dst->pool, vol_src->pool));
ignore_value(VIR_STRDUP_QUIET(vol_dst->name, vol_src->name));
ignore_value(VIR_STRDUP_QUIET(vol_dst->key, vol_src->key));
if (VIR_STRDUP(vol_dst->pool, vol_src->pool) < 0)
return -1;
if (VIR_STRDUP(vol_dst->name, vol_src->name) < 0) {
VIR_FREE(vol_dst->pool);
return -1;
}
if (VIR_STRDUP(vol_dst->key, vol_src->key) < 0) {
VIR_FREE(vol_dst->pool);
VIR_FREE(vol_dst->name);
return -1;
}
return 0;
}
static void
static int
make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src)
{
ignore_value(VIR_STRDUP_QUIET(dev_dst->name, dev_src->name));
if (VIR_STRDUP(dev_dst->name, dev_src->name) < 0)
return -1;
return 0;
}
static void
static int
make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecretPtr secret_src)
{
memcpy(secret_dst->uuid, secret_src->uuid, VIR_UUID_BUFLEN);
secret_dst->usageType = secret_src->usageType;
ignore_value(VIR_STRDUP_QUIET(secret_dst->usageID, secret_src->usageID));
if (VIR_STRDUP(secret_dst->usageID, secret_src->usageID) < 0)
return -1;
return 0;
}
static void
static int
make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src)
{
ignore_value(VIR_STRDUP_QUIET(nwfilter_dst->name, nwfilter_src->name));
if (VIR_STRDUP(nwfilter_dst->name, nwfilter_src->name) < 0)
return -1;
memcpy(nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN);
return 0;
}
static void
static int
make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding *binding_dst, virNWFilterBindingPtr binding_src)
{
ignore_value(VIR_STRDUP_QUIET(binding_dst->portdev, binding_src->portdev));
ignore_value(VIR_STRDUP_QUIET(binding_dst->filtername, binding_src->filtername));
if (VIR_STRDUP(binding_dst->portdev, binding_src->portdev) < 0)
return -1;
if (VIR_STRDUP(binding_dst->filtername, binding_src->filtername) < 0) {
VIR_FREE(binding_dst->portdev);
return -1;
}
return 0;
}
static void
static int
make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src)
{
ignore_value(VIR_STRDUP_QUIET(snapshot_dst->name, snapshot_src->name));
make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain);
if (VIR_STRDUP(snapshot_dst->name, snapshot_src->name) < 0)
return -1;
if (make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain) < 0) {
VIR_FREE(snapshot_dst->name);
return -1;
}
return 0;
}
static int

View File

@ -786,12 +786,12 @@ elsif ($mode eq "server") {
if ($call->{ProcName} eq "DomainCreateWithFlags") {
# SPECIAL: virDomainCreateWithFlags updates the given
# domain object instead of returning a new one
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);");
push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
$single_ret_var = undef;
$single_ret_by_ref = 1;
} else {
push(@vars_list, "vir${type_name}Ptr $2 = NULL");
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);");
push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
push(@free_list,
" virObjectUnref($2);");
$single_ret_var = $2;
@ -907,11 +907,11 @@ elsif ($mode eq "server") {
if ($1 eq "client") {
push(@vars_list, "virNetServer${type_name}Ptr $2 = NULL");
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);");
push(@ret_list, "make_nonnull_server(&ret->$2.srv, srv);");
push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
push(@ret_list, "if (make_nonnull_server(&ret->$2.srv, srv) < 0)\n goto cleanup;\n");
} else {
push(@vars_list, "virNet${type_name}Ptr $2 = NULL");
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);");
push(@ret_list, "if (make_nonnull_$1(&ret->$2, $2) < 0)\n goto cleanup;\n");
}
push(@free_list,
@ -1175,12 +1175,15 @@ elsif ($mode eq "server") {
print " ret->$single_ret_list_name.${single_ret_list_name}_len = nresults;\n";
if ($modern_ret_is_nested) {
print " for (i = 0; i < nresults; i++) {\n";
print " make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]);\n";
print " make_nonnull_$modern_ret_nested_struct_name(&ret->$single_ret_list_name.${single_ret_list_name}_val[i].srv, srv);\n";
print " if (make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]) < 0)\n";
print " goto cleanup;\n";
print " if (make_nonnull_$modern_ret_nested_struct_name(&ret->$single_ret_list_name.${single_ret_list_name}_val[i].srv, srv) < 0)\n";
print " goto cleanup;\n";
print " }\n";
} else {
print " for (i = 0; i < nresults; i++)\n";
print " make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]);\n";
print " if (make_nonnull_$modern_ret_struct_name(ret->$single_ret_list_name.${single_ret_list_name}_val + i, result[i]) < 0)\n";
print " goto cleanup;\n";
}
print " } else {\n";
print " ret->$single_ret_list_name.${single_ret_list_name}_len = 0;\n";