--- daemon/libvirtd-config.c | 37 ++++++++++--------- daemon/libvirtd.c | 17 +++++---- daemon/remote.c | 94 ++++++++++++++++++++---------------------------- 3 files changed, 66 insertions(+), 82 deletions(-) diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index efb564e..df2bc7b 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -59,15 +59,14 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, key); return -1; } - list[0] = strdup(p->str); - list[1] = NULL; - if (list[0] == NULL) { + if (VIR_STRDUP(list[0], p->str) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("failed to allocate memory for %s config list value"), key); VIR_FREE(list); return -1; } + list[1] = NULL; break; case VIR_CONF_LIST: { @@ -90,8 +89,7 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, VIR_FREE(list); return -1; } - list[i] = strdup(pp->str); - if (list[i] == NULL) { + if (VIR_STRDUP(list[i], pp->str) < 0) { int j; for (j = 0 ; j < i ; j++) VIR_FREE(list[j]); @@ -136,8 +134,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and "goto" the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do { \ @@ -146,7 +144,7 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) < 0) \ goto error; \ VIR_FREE(data->var_name); \ - if (!(data->var_name = strdup(p->str))) { \ + if (VIR_STRDUP(data->var_name, p->str) < 0) { \ virReportOOMError(); \ goto error; \ } \ @@ -200,7 +198,7 @@ int daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { - if (!(*configfile = strdup(SYSCONFDIR "/libvirt/libvirtd.conf"))) + if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/libvirtd.conf") < 0) goto no_memory; } else { char *configdir = NULL; @@ -238,9 +236,9 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) data->listen_tls = 1; data->listen_tcp = 0; - if (!(data->tls_port = strdup(LIBVIRTD_TLS_PORT))) + if (VIR_STRDUP(data->tls_port, LIBVIRTD_TLS_PORT) < 0) goto no_memory; - if (!(data->tcp_port = strdup(LIBVIRTD_TCP_PORT))) + if (VIR_STRDUP(data->tcp_port, LIBVIRTD_TCP_PORT) < 0) goto no_memory; /* Only default to PolicyKit if running as root */ @@ -256,13 +254,14 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) } #endif - if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) - data->unix_sock_rw_perms = strdup("0777"); /* Allow world */ - else - data->unix_sock_rw_perms = strdup("0700"); /* Allow user only */ - data->unix_sock_ro_perms = strdup("0777"); /* Always allow world */ - if (!data->unix_sock_ro_perms || - !data->unix_sock_rw_perms) + if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) + goto no_memory; + } else { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0700") < 0) + goto no_memory; + } + if (VIR_STRDUP(data->unix_sock_ro_perms, "0777") < 0) goto no_memory; #if WITH_SASL @@ -382,7 +381,7 @@ daemonConfigLoadOptions(struct daemonConfig *data, */ if (data->auth_unix_rw == REMOTE_AUTH_POLKIT) { VIR_FREE(data->unix_sock_rw_perms); - if (!(data->unix_sock_rw_perms = strdup("0777"))) { + if (VIR_STRDUP(data->unix_sock_rw_perms, "0777") < 0) { virReportOOMError(); goto error; } diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 9f81a0f..07c064d 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -241,7 +241,7 @@ daemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { - if (!(*pidfile = strdup(LOCALSTATEDIR "/run/libvirtd.pid"))) + if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/libvirtd.pid") < 0) goto no_memory; } else { char *rundir = NULL; @@ -287,9 +287,9 @@ daemonUnixSocketPaths(struct daemonConfig *config, goto no_memory; } else { if (privileged) { - if (!(*sockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock"))) + if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0) goto no_memory; - if (!(*rosockfile = strdup(LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"))) + if (VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro") < 0) goto no_memory; } else { char *rundir = NULL; @@ -961,7 +961,10 @@ static int migrateProfile(void) config_home = getenv("XDG_CONFIG_HOME"); if (config_home && config_home[0] != '\0') { - xdg_dir = strdup(config_home); + if (VIR_STRDUP(xdg_dir, config_home) < 0) { + virReportOOMError(); + goto cleanup; + } } else { if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) { goto cleanup; @@ -1172,7 +1175,7 @@ int main(int argc, char **argv) { case 'p': VIR_FREE(pid_file); - if (!(pid_file = strdup(optarg))) { + if (VIR_STRDUP(pid_file, optarg) < 0) { VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); } @@ -1180,7 +1183,7 @@ int main(int argc, char **argv) { case 'f': VIR_FREE(remote_config_file); - if (!(remote_config_file = strdup(optarg))) { + if (VIR_STRDUP(remote_config_file, optarg) < 0) { VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); } @@ -1287,7 +1290,7 @@ int main(int argc, char **argv) { /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - run_dir = strdup(LOCALSTATEDIR "/run/libvirt"); + ignore_value(VIR_STRDUP(run_dir, LOCALSTATEDIR "/run/libvirt")); } else { run_dir = virGetUserRuntimeDirectory(); diff --git a/daemon/remote.c b/daemon/remote.c index 8c79680..fa8dedd 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -234,11 +234,9 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - data.srcPath = strdup(srcPath); - if (data.srcPath == NULL) + if (VIR_STRDUP(data.srcPath, srcPath) < 0) goto mem_error; - data.devAlias = strdup(devAlias); - if (data.devAlias == NULL) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; make_nonnull_domain(&data.dom, dom); data.action = action; @@ -275,15 +273,12 @@ static int remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS /* build return data */ memset(&data, 0, sizeof(data)); - data.srcPath = strdup(srcPath); - if (data.srcPath == NULL) + if (VIR_STRDUP(data.srcPath, srcPath) < 0) goto mem_error; - data.devAlias = strdup(devAlias); - if (data.devAlias == NULL) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; data.action = action; - data.reason = strdup(reason); - if (data.reason == NULL) + if (VIR_STRDUP(data.reason, reason) < 0) goto mem_error; make_nonnull_domain(&data.dom, dom); @@ -334,22 +329,17 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, data.phase = phase; data.local.family = local->family; data.remote.family = remote->family; - data.authScheme = strdup(authScheme); - if (data.authScheme == NULL) + if (VIR_STRDUP(data.authScheme, authScheme) < 0) goto mem_error; - data.local.node = strdup(local->node); - if (data.local.node == NULL) + if (VIR_STRDUP(data.local.node, local->node) < 0) goto mem_error; - data.local.service = strdup(local->service); - if (data.local.service == NULL) + if (VIR_STRDUP(data.local.service, local->service) < 0) goto mem_error; - data.remote.node = strdup(remote->node); - if (data.remote.node == NULL) + if (VIR_STRDUP(data.remote.node, remote->node) < 0) goto mem_error; - data.remote.service = strdup(remote->service); - if (data.remote.service == NULL) + if (VIR_STRDUP(data.remote.service, remote->service) < 0) goto mem_error; data.subject.subject_len = subject->nidentity; @@ -357,11 +347,9 @@ static int remoteRelayDomainEventGraphics(virConnectPtr conn ATTRIBUTE_UNUSED, goto mem_error; for (i = 0 ; i < data.subject.subject_len ; i++) { - data.subject.subject_val[i].type = strdup(subject->identities[i].type); - if (data.subject.subject_val[i].type == NULL) + if (VIR_STRDUP(data.subject.subject_val[i].type, subject->identities[i].type) < 0) goto mem_error; - data.subject.subject_val[i].name = strdup(subject->identities[i].name); - if (data.subject.subject_val[i].name == NULL) + if (VIR_STRDUP(data.subject.subject_val[i].name, subject->identities[i].name) < 0) goto mem_error; } make_nonnull_domain(&data.dom, dom); @@ -407,8 +395,7 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - data.path = strdup(path); - if (data.path == NULL) + if (VIR_STRDUP(data.path, path) < 0) goto mem_error; data.type = type; data.status = status; @@ -473,17 +460,17 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr conn ATTRIBUTE_UNUSED, memset(&data, 0, sizeof(data)); if (oldSrcPath && ((VIR_ALLOC(oldSrcPath_p) < 0) || - !(*oldSrcPath_p = strdup(oldSrcPath)))) + VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0)) goto mem_error; if (newSrcPath && ((VIR_ALLOC(newSrcPath_p) < 0) || - !(*newSrcPath_p = strdup(newSrcPath)))) + VIR_STRDUP(*newSrcPath_p, newSrcPath) < 0)) goto mem_error; data.oldSrcPath = oldSrcPath_p; data.newSrcPath = newSrcPath_p; - if (!(data.devAlias = strdup(devAlias))) + if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto mem_error; data.reason = reason; @@ -520,7 +507,7 @@ static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED, /* build return data */ memset(&data, 0, sizeof(data)); - if (!(data.devAlias = strdup(devAlias))) { + if (VIR_STRDUP(data.devAlias, devAlias) < 0) { virReportOOMError(); return -1; } @@ -850,8 +837,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, } /* remoteDispatchClientRequest will free this: */ - val[j].field = strdup(params[i].field); - if (val[j].field == NULL) { + if (VIR_STRDUP(val[j].field, params[i].field) < 0) { virReportOOMError(); goto cleanup; } @@ -876,9 +862,8 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, val[j].value.remote_typed_param_value_u.b = params[i].value.b; break; case VIR_TYPED_PARAM_STRING: - val[j].value.remote_typed_param_value_u.s = - strdup(params[i].value.s); - if (val[j].value.remote_typed_param_value_u.s == NULL) { + if (VIR_STRDUP(val[j].value.remote_typed_param_value_u.s, + params[i].value.s) < 0) { virReportOOMError(); goto cleanup; } @@ -966,9 +951,8 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val, args_params_val[i].value.remote_typed_param_value_u.b; break; case VIR_TYPED_PARAM_STRING: - params[i].value.s = - strdup(args_params_val[i].value.remote_typed_param_value_u.s); - if (params[i].value.s == NULL) { + if (VIR_STRDUP(params[i].value.s, + args_params_val[i].value.remote_typed_param_value_u.s) < 0) { virReportOOMError(); goto cleanup; } @@ -2145,8 +2129,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED, for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - ret->params.params_val[i].field = strdup(params[i].field); - if (ret->params.params_val[i].field == NULL) + if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0) goto no_memory; ret->params.params_val[i].value = params[i].value; @@ -2223,8 +2206,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED, for (i = 0; i < nparams; ++i) { /* remoteDispatchClientRequest will free this: */ - ret->params.params_val[i].field = strdup(params[i].field); - if (ret->params.params_val[i].field == NULL) + if (VIR_STRDUP(ret->params.params_val[i].field, params[i].field) < 0) goto no_memory; ret->params.params_val[i].value = params[i].value; @@ -3100,7 +3082,7 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr server ATTRIBUTE_UNUSED, virReportOOMError(); goto cleanup; } - if (!(*parent_p = strdup(parent))) { + if (VIR_STRDUP(*parent_p, parent) < 0) { VIR_FREE(parent_p); virReportOOMError(); goto cleanup; @@ -4769,14 +4751,14 @@ static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) { dom_dst->id = dom_src->id; - dom_dst->name = strdup(dom_src->name); + ignore_value(VIR_STRDUP_QUIET(dom_dst->name , dom_src->name)); memcpy(dom_dst->uuid, dom_src->uuid, VIR_UUID_BUFLEN); } static void make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src) { - net_dst->name = strdup(net_src->name); + ignore_value(VIR_STRDUP_QUIET(net_dst->name, net_src->name)); memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN); } @@ -4784,29 +4766,29 @@ static void make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) { - interface_dst->name = strdup(interface_src->name); - interface_dst->mac = strdup(interface_src->mac); + ignore_value(VIR_STRDUP_QUIET(interface_dst->name, interface_src->name)); + ignore_value(VIR_STRDUP_QUIET(interface_dst->mac, interface_src->mac)); } static void make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src) { - pool_dst->name = strdup(pool_src->name); + ignore_value(VIR_STRDUP_QUIET(pool_dst->name, pool_src->name)); memcpy(pool_dst->uuid, pool_src->uuid, VIR_UUID_BUFLEN); } static void make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src) { - vol_dst->pool = strdup(vol_src->pool); - vol_dst->name = strdup(vol_src->name); - vol_dst->key = strdup(vol_src->key); + 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)); } static void make_nonnull_node_device(remote_nonnull_node_device *dev_dst, virNodeDevicePtr dev_src) { - dev_dst->name = strdup(dev_src->name); + ignore_value(VIR_STRDUP_QUIET(dev_dst->name, dev_src->name)); } static void @@ -4814,20 +4796,20 @@ 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; - secret_dst->usageID = strdup(secret_src->usageID); + ignore_value(VIR_STRDUP_QUIET(secret_dst->usageID, secret_src->usageID)); } static void make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src) { - nwfilter_dst->name = strdup(nwfilter_src->name); + ignore_value(VIR_STRDUP_QUIET(nwfilter_dst->name, nwfilter_src->name)); memcpy(nwfilter_dst->uuid, nwfilter_src->uuid, VIR_UUID_BUFLEN); } static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src) { - snapshot_dst->name = strdup(snapshot_src->name); + ignore_value(VIR_STRDUP_QUIET(snapshot_dst->name, snapshot_src->name)); make_nonnull_domain(&snapshot_dst->dom, snapshot_src->domain); } @@ -4844,7 +4826,7 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, goto no_memory; for (i = 0; i < nerrors; i++) { - if (!(val[i].disk = strdup(errors[i].disk))) + if (VIR_STRDUP(val[i].disk, errors[i].disk) < 0) goto no_memory; val[i].error = errors[i].error; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list