From nobody Mon Feb 9 12:25:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537450149528709.9078884109197; Thu, 20 Sep 2018 06:29:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9ACC3001938; Thu, 20 Sep 2018 13:29:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0349B1882C; Thu, 20 Sep 2018 13:29:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1E1C84BB75; Thu, 20 Sep 2018 13:29:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KDT4N1005088 for ; Thu, 20 Sep 2018 09:29:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5628316E5A; Thu, 20 Sep 2018 13:29:04 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E54019486; Thu, 20 Sep 2018 13:29:03 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 15:28:49 +0200 Message-Id: <20180920132852.20280-4-fidencio@redhat.com> In-Reply-To: <20180920132852.20280-1-fidencio@redhat.com> References: <20180920132852.20280-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [libvirt PATCH v7 3/6] xen_common: Change xenConfigGetString to using virConfGetValueString X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 20 Sep 2018 13:29:07 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 This change actually changes the behaviour of xenConfigGetString() as now it returns a newly-allocated string. Unfortunately, there's not much that can be done in order to avoid that and all the callers have to be changed in order to avoid leaking the return value. Also, as a side-effect of the change above, the function now takes a "char **" argument instead of a "const char **" one. Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: John Ferlan --- src/xenconfig/xen_common.c | 84 ++++++++++++++++++++------------------ src/xenconfig/xen_common.h | 2 +- src/xenconfig/xen_xl.c | 10 +++-- src/xenconfig/xen_xm.c | 7 ++-- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 587bab2b19..7b3e5c3b44 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -228,26 +228,28 @@ xenConfigGetUUID(virConfPtr conf, const char *name, u= nsigned char *uuid) int xenConfigGetString(virConfPtr conf, const char *name, - const char **value, + char **value, const char *def) { - virConfValuePtr val; + char *string =3D NULL; + int rc; =20 *value =3D NULL; - if (!(val =3D virConfGetValue(conf, name))) { - *value =3D def; + if ((rc =3D virConfGetValueString(conf, name, &string)) < 0) + return -1; + + if (rc =3D=3D 0) { + if (VIR_STRDUP(*value, def) < 0) + return -1; return 0; } =20 - if (val->type !=3D VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("config value %s was malformed"), name); - return -1; + if (!string) { + if (VIR_STRDUP(*value, def) < 0) + return -1; + } else { + *value =3D string; } - if (!val->str) - *value =3D def; - else - *value =3D val->str; return 0; } =20 @@ -345,32 +347,34 @@ xenParseTimeOffset(virConfPtr conf, virDomainDefPtr d= ef) static int xenParseEventsActions(virConfPtr conf, virDomainDefPtr def) { - const char *str =3D NULL; + VIR_AUTOFREE(char *) on_poweroff =3D NULL; + VIR_AUTOFREE(char *) on_reboot =3D NULL; + VIR_AUTOFREE(char *) on_crash =3D NULL; =20 - if (xenConfigGetString(conf, "on_poweroff", &str, "destroy") < 0) + if (xenConfigGetString(conf, "on_poweroff", &on_poweroff, "destroy") <= 0) return -1; =20 - if ((def->onPoweroff =3D virDomainLifecycleActionTypeFromString(str)) = < 0) { + if ((def->onPoweroff =3D virDomainLifecycleActionTypeFromString(on_pow= eroff)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_poweroff"), str); + _("unexpected value %s for on_poweroff"), on_powero= ff); return -1; } =20 - if (xenConfigGetString(conf, "on_reboot", &str, "restart") < 0) + if (xenConfigGetString(conf, "on_reboot", &on_reboot, "restart") < 0) return -1; =20 - if ((def->onReboot =3D virDomainLifecycleActionTypeFromString(str)) < = 0) { + if ((def->onReboot =3D virDomainLifecycleActionTypeFromString(on_reboo= t)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_reboot"), str); + _("unexpected value %s for on_reboot"), on_reboot); return -1; } =20 - if (xenConfigGetString(conf, "on_crash", &str, "restart") < 0) + if (xenConfigGetString(conf, "on_crash", &on_crash, "restart") < 0) return -1; =20 - if ((def->onCrash =3D virDomainLifecycleActionTypeFromString(str)) < 0= ) { + if ((def->onCrash =3D virDomainLifecycleActionTypeFromString(on_crash)= ) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_crash"), str); + _("unexpected value %s for on_crash"), on_crash); return -1; } =20 @@ -488,7 +492,8 @@ xenParseCPUFeatures(virConfPtr conf, virDomainXMLOptionPtr xmlopt) { unsigned long count =3D 0; - const char *str =3D NULL; + VIR_AUTOFREE(char *) cpus =3D NULL; + VIR_AUTOFREE(char *) tsc_mode =3D NULL; int val =3D 0; virDomainTimerDefPtr timer; =20 @@ -509,16 +514,16 @@ xenParseCPUFeatures(virConfPtr conf, return -1; } =20 - if (xenConfigGetString(conf, "cpus", &str, NULL) < 0) + if (xenConfigGetString(conf, "cpus", &cpus, NULL) < 0) return -1; =20 - if (str && (virBitmapParse(str, &def->cpumask, 4096) < 0)) + if (cpus && (virBitmapParse(cpus, &def->cpumask, 4096) < 0)) return -1; =20 - if (xenConfigGetString(conf, "tsc_mode", &str, NULL) < 0) + if (xenConfigGetString(conf, "tsc_mode", &tsc_mode, NULL) < 0) return -1; =20 - if (str) { + if (tsc_mode) { if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0 || VIR_ALLOC(timer) < 0) return -1; @@ -528,11 +533,11 @@ xenParseCPUFeatures(virConfPtr conf, timer->tickpolicy =3D -1; timer->mode =3D VIR_DOMAIN_TIMER_MODE_AUTO; timer->track =3D -1; - if (STREQ_NULLABLE(str, "always_emulate")) + if (STREQ_NULLABLE(tsc_mode, "always_emulate")) timer->mode =3D VIR_DOMAIN_TIMER_MODE_EMULATE; - else if (STREQ_NULLABLE(str, "native")) + else if (STREQ_NULLABLE(tsc_mode, "native")) timer->mode =3D VIR_DOMAIN_TIMER_MODE_NATIVE; - else if (STREQ_NULLABLE(str, "native_paravirt")) + else if (STREQ_NULLABLE(tsc_mode, "native_paravirt")) timer->mode =3D VIR_DOMAIN_TIMER_MODE_PARAVIRT; =20 def->clock.timers[def->clock.ntimers - 1] =3D timer; @@ -746,15 +751,15 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFo= rmat) { - const char *str; virConfValuePtr value =3D NULL; virDomainChrDefPtr chr =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - if (xenConfigGetString(conf, "parallel", &str, NULL) < 0) + VIR_AUTOFREE(char *) parallel =3D NULL; + if (xenConfigGetString(conf, "parallel", ¶llel, NULL) < 0) goto cleanup; - if (str && STRNEQ(str, "none") && - !(chr =3D xenParseSxprChar(str, NULL))) + if (parallel && STRNEQ(parallel, "none") && + !(chr =3D xenParseSxprChar(parallel, NULL))) goto cleanup; if (chr) { if (VIR_ALLOC_N(def->parallels, 1) < 0) @@ -801,11 +806,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) value =3D value->next; } } else { + VIR_AUTOFREE(char *) serial =3D NULL; /* If domain is not using multiple serial ports we parse data = old way */ - if (xenConfigGetString(conf, "serial", &str, NULL) < 0) + if (xenConfigGetString(conf, "serial", &serial, NULL) < 0) goto cleanup; - if (str && STRNEQ(str, "none") && - !(chr =3D xenParseSxprChar(str, NULL))) + if (serial && STRNEQ(serial, "none") && + !(chr =3D xenParseSxprChar(serial, NULL))) goto cleanup; if (chr) { if (VIR_ALLOC_N(def->serials, 1) < 0) @@ -1049,7 +1055,7 @@ xenParseVifList(virConfPtr conf, virDomainDefPtr def,= const char *vif_typename) static int xenParseEmulatedDevices(virConfPtr conf, virDomainDefPtr def) { - const char *str; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { if (xenConfigGetString(conf, "soundhw", &str, NULL) < 0) @@ -1068,7 +1074,7 @@ static int xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) { virCapsDomainDataPtr capsdata =3D NULL; - const char *str; + VIR_AUTOFREE(char *) str =3D NULL; int hvm =3D 0, ret =3D -1; =20 if (xenConfigCopyString(conf, "name", &def->name) < 0) diff --git a/src/xenconfig/xen_common.h b/src/xenconfig/xen_common.h index 3b7a5db4f3..a26c9e60c4 100644 --- a/src/xenconfig/xen_common.h +++ b/src/xenconfig/xen_common.h @@ -33,7 +33,7 @@ =20 int xenConfigGetString(virConfPtr conf, const char *name, - const char **value, + char **value, const char *def); =20 int xenConfigGetBool(virConfPtr conf, const char *name, int *value, int de= f); diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 19b6604e05..7250e5735d 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -65,7 +65,9 @@ extern int xlu_disk_parse(XLU_Config *cfg, static int xenParseCmdline(virConfPtr conf, char **r_cmdline) { char *cmdline =3D NULL; - const char *root, *extra, *buf; + VIR_AUTOFREE(char *) root =3D NULL; + VIR_AUTOFREE(char *) extra =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (xenConfigGetString(conf, "cmdline", &buf, NULL) < 0) return -1; @@ -104,8 +106,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virC= apsPtr caps) size_t i; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - const char *bios; - const char *boot; + VIR_AUTOFREE(char *) bios =3D NULL; + VIR_AUTOFREE(char *) boot =3D NULL; int val =3D 0; =20 if (xenConfigGetString(conf, "bios", &bios, NULL) < 0) @@ -255,7 +257,7 @@ xenTranslateCPUFeature(const char *feature_name, bool f= rom_libxl) static int xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def) { - const char *cpuid_str =3D NULL; + VIR_AUTOFREE(char *) cpuid_str =3D NULL; char **cpuid_pairs =3D NULL; char **name_and_value =3D NULL; size_t i; diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index 7b60f25ec1..909e8fad40 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -44,7 +44,7 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def) size_t i; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - const char *boot; + VIR_AUTOFREE(char *) boot =3D NULL; =20 if (VIR_ALLOC(def->os.loader) < 0 || xenConfigCopyString(conf, "kernel", &def->os.loader->path) < 0) @@ -72,7 +72,8 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def) def->os.nBootDevs++; } } else { - const char *extra, *root; + VIR_AUTOFREE(char *) extra =3D NULL; + VIR_AUTOFREE(char *) root =3D NULL; =20 if (xenConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader= ) < 0) return -1; @@ -417,7 +418,7 @@ xenFormatXMDisks(virConfPtr conf, virDomainDefPtr def) static int xenParseXMInputDevs(virConfPtr conf, virDomainDefPtr def) { - const char *str; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { if (xenConfigGetString(conf, "usbdevice", &str, NULL) < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list