From nobody Fri Dec 12 14:06:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1764252251; cv=none; d=zohomail.com; s=zohoarc; b=NpXmbyZiElDSuj/HoFM1AQgmQWm8rdcFxAoSwgLC8G4mRN2hCQAr5ugmHDZemcRgQ6NDG/lpHRvrJ8KuP29Nlsn8Kpttx3YF/LoH0w1GZbaG08cJpn6Hn4DRUmXARXERx9R4mFB5sLCsrv+yaPITOAIjMjWZRcZT+TKjVGqONF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764252251; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=KXtHhTdBTStlWs88xnerqcG2Y/3aET6czTjiRyPX0hE=; b=H2bOD6m3RPEOHhU7YKP6/TxsL4aZzCMHlabiMjCCHAABcWGVKymYMAtmGikRwRdNnN9IKUft601WdQK58rVMvcpSOGnTXpleFWzCnWDB7YzTbG1nebj5cpBvk7vj/ZNwO1yxz+cICBCgu2Z8h4qCBauDaDvCYjEr/kxLE//KCb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1764252244791876.7202026607151; Thu, 27 Nov 2025 06:04:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id CCA6C44B60; Thu, 27 Nov 2025 09:03:59 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 2ACF444D90; Thu, 27 Nov 2025 08:55:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id C908041996; Thu, 27 Nov 2025 08:52:39 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 6428F44BE0 for ; Thu, 27 Nov 2025 08:51:18 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-RxtVnZYdPHmrbL52uT6pSQ-1; Thu, 27 Nov 2025 08:51:16 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0038C180049F for ; Thu, 27 Nov 2025 13:51:16 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C64E1800451 for ; Thu, 27 Nov 2025 13:51:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764251478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KXtHhTdBTStlWs88xnerqcG2Y/3aET6czTjiRyPX0hE=; b=Rc1w7szOpVqASWan0lXk4v78p8Apf1rwn79gdkFbKb+Nh7kY/pRgzfZFPfOANv/1So0pIY djWQnwCmuJSGsQtqUMRF2Ce2JFE72h6xXJpuvsRoblLPjx7iRobJRWPl75qPSndAhLI503 FX179cJP/qq6X/NcwwfLeWaXjPTpQww= X-MC-Unique: RxtVnZYdPHmrbL52uT6pSQ-1 X-Mimecast-MFC-AGG-ID: RxtVnZYdPHmrbL52uT6pSQ_1764251476 To: devel@lists.libvirt.org Subject: [PATCH 8/8] lib: Avoid changing const strings via strchr() and friends Date: Thu, 27 Nov 2025 14:51:03 +0100 Message-ID: <8efac77783661f47efba79021eb2e9801c3194ce.1764251323.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 83neDsU8FLU6PdIzrRHg_SAWICrtTh6FjSPODZEiMTw_1764251476 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6FRIEFQBQKFQB3W5F5ETU6CN4UBY5Q4Q X-Message-ID-Hash: 6FRIEFQBQKFQB3W5F5ETU6CN4UBY5Q4Q X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1764252256016019200 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik There's new commit in glibc [1] which makes memchr(), strchr(), strrchr(), strpbrk() and strstr() reflect type of the input string. If it's a constant string, then the return type of these functions is also 'const char *'. But this change tickles -Wincompatible-pointer-types-discards-qualifiers warning. And indeed, there are some places where we use a 'char *' typed variable to store the retval, or even misuse the fact 'char *' is returned and modify const string. To fix this, a couple of different approaches is used: a) switch variable type to 'const char *', b) switch argument to 'char *' (in a few places we have strdup()-ed) the const string already, c) strdup() the string and use b). 1: https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommit;h=3Dcd748a63ab1a7ae= 846175c532a3daab341c62690 Signed-off-by: Michal Privoznik --- src/interface/interface_backend_udev.c | 2 +- src/libxl/xen_common.c | 10 +++++----- src/libxl/xen_xm.c | 10 ++++++---- src/node_device/node_device_udev.c | 2 +- src/nwfilter/nwfilter_ebiptables_driver.c | 4 ++-- src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_nbdkit.c | 2 +- src/rpc/virnetsshsession.c | 5 +++-- src/storage/storage_util.c | 2 +- src/storage_file/storage_source.c | 4 ++-- src/util/vircgroup.c | 2 +- src/util/virfile.c | 2 +- src/util/virstoragefile.c | 4 ++-- src/util/virsysinfo.c | 8 ++++---- src/util/virxml.c | 3 ++- src/vmware/vmware_conf.c | 2 +- tools/vsh.c | 6 +++--- 17 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 48eacdcdc2..c6d14aa803 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -927,7 +927,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) g_autoptr(virInterfaceDef) ifacedef =3D NULL; unsigned int mtu; const char *mtu_str; - char *vlan_parent_dev =3D NULL; + const char *vlan_parent_dev =3D NULL; const char *devtype; =20 /* Allocate our interface definition structure */ diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 666c6cae20..890ef11723 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -802,20 +802,20 @@ static virDomainChrDef * xenParseSxprChar(const char *value, const char *tty) { - const char *prefix; + g_autofree char *prefix =3D NULL; char *tmp; virDomainChrDef *def; =20 if (!(def =3D virDomainChrDefNew(NULL))) return NULL; =20 - prefix =3D value; + prefix =3D g_strdup(value); =20 if (g_path_is_absolute(value)) { def->source->type =3D VIR_DOMAIN_CHR_TYPE_DEV; def->source->data.file.path =3D g_strdup(value); } else { - if ((tmp =3D strchr(value, ':')) !=3D NULL) { + if ((tmp =3D strchr(prefix, ':')) !=3D NULL) { *tmp =3D '\0'; value =3D tmp + 1; } @@ -1019,7 +1019,7 @@ xenParseCharDev(virConf *conf, virDomainDef *def, con= st char *nativeFormat) static int xenParseVifBridge(virDomainNetDef *net, const char *bridge) { - char *vlanstr; + const char *vlanstr; unsigned int tag; =20 if ((vlanstr =3D strchr(bridge, '.'))) { @@ -1144,7 +1144,7 @@ xenParseVif(char *entry, const char *vif_typename) =20 for (keyval =3D keyvals; keyval && *keyval; keyval++) { const char *key =3D *keyval; - char *val =3D strchr(key, '=3D'); + const char *val =3D strchr(key, '=3D'); =20 virSkipSpaces(&key); =20 diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 274b35153b..4327a9391d 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -154,9 +154,11 @@ xenParseXMDisk(char *entry, int hvm) src =3D virDomainDiskGetSource(disk); if (src) { size_t len; + const char *sep; + /* The main type phy:, file:, tap: ... */ - if ((tmp =3D strchr(src, ':')) !=3D NULL) { - len =3D tmp - src; + if ((sep =3D strchr(src, ':')) !=3D NULL) { + len =3D sep - src; tmp =3D g_strndup(src, len); =20 virDomainDiskSetDriver(disk, tmp); @@ -173,9 +175,9 @@ xenParseXMDisk(char *entry, int hvm) STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap2")) { char *driverType; =20 - if (!(tmp =3D strchr(src, ':'))) + if (!(sep =3D strchr(src, ':'))) goto error; - len =3D tmp - src; + len =3D sep - src; =20 driverType =3D g_strndup(src, len); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 27e62febe8..20a525bcec 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1187,7 +1187,7 @@ static int udevGetCCWAddress(const char *sysfs_path, virNodeDevCapData *data) { - char *p; + const char *p; g_autofree virCCWDeviceAddress *ccw_addr =3D g_new0(virCCWDeviceAddres= s, 1); =20 if ((p =3D strrchr(sysfs_path, '/')) =3D=3D NULL || diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 4578152670..859347409c 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2604,7 +2604,7 @@ ebtablesRemoveSubChainsQuery(virFirewall *fw, const char *chainprefixes =3D opaque; =20 for (i =3D 0; lines[i] !=3D NULL; i++) { - char *tmp =3D strstr(lines[i], "-j "); + const char *tmp =3D strstr(lines[i], "-j "); =20 VIR_DEBUG("Considering '%s'", lines[i]); =20 @@ -2708,7 +2708,7 @@ ebtablesRenameTmpSubAndRootChainsQuery(virFirewall *f= w, char newchain[MAX_CHAINNAME_LENGTH]; =20 for (i =3D 0; lines[i] !=3D NULL; i++) { - char *tmp =3D strstr(lines[i], "-j "); + const char *tmp =3D strstr(lines[i], "-j "); =20 VIR_DEBUG("Considering '%s'", lines[i]); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 494d7ef515..a602b1e65b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -241,7 +241,7 @@ qemuMonitorJSONIOProcess(qemuMonitor *mon, /*VIR_DEBUG("Data %d bytes [%s]", len, data);*/ =20 while (used < len) { - char *nl =3D strstr(data + used, LINE_ENDING); + const char *nl =3D strstr(data + used, LINE_ENDING); =20 if (nl) { int got =3D nl - (data + used); diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index c1bc6bc363..542a6b1f44 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -146,7 +146,7 @@ qemuNbdkitCapsQueryBuildConfig(qemuNbdkitCaps *nbdkit) size_t i; g_autofree char *output =3D NULL; g_auto(GStrv) lines =3D NULL; - const char *line; + char *line; g_autoptr(virCommand) cmd =3D virCommandNewArgList(nbdkit->path, "--dump-config", NULL); diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 316521d4cf..83c8630480 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -216,13 +216,14 @@ virNetSSHKbIntCb(const char *name G_GNUC_UNUSED, =20 /* fill data structures for auth callback */ for (i =3D 0; i < num_prompts; i++) { - askcred[i].prompt =3D g_strdup((char*)prompts[i].text); + char *prompt =3D g_strdup((char*)prompts[i].text); =20 /* remove colon and trailing spaces from prompts, as default behav= ior * of libvirt's auth callback is to add them */ - if ((tmp =3D strrchr(askcred[i].prompt, ':'))) + if ((tmp =3D strrchr(prompt, ':'))) *tmp =3D '\0'; =20 + askcred[i].prompt =3D prompt; askcred[i].type =3D prompts[i].echo ? credtype_echo : credtype_noe= cho; } =20 diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 8f7fc6cc01..e2b41de1f2 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3773,7 +3773,7 @@ getOldStyleBlockDevice(const char *lun_path G_GNUC_UN= USED, const char *block_name, char **block_device) { - char *blockp =3D NULL; + const char *blockp =3D NULL; =20 /* old-style; just parse out the sd */ if (!(blockp =3D strrchr(block_name, ':'))) { diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 843910a0d8..1883225a8b 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -45,8 +45,8 @@ VIR_LOG_INIT("storage_source"); static bool virStorageSourceBackinStoreStringIsFile(const char *backing) { - char *colon; - char *slash; + const char *colon; + const char *slash; =20 if (!backing) return false; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 532a7e5690..3d66d3acb2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -517,7 +517,7 @@ int virCgroupSetValueRaw(const char *path, const char *value) { - char *tmp; + const char *tmp; =20 VIR_DEBUG("Set path '%s' to value '%s'", path, value); if (virFileWriteStr(path, value, 0) < 0) { diff --git a/src/util/virfile.c b/src/util/virfile.c index a5c9fbe0d9..f195d02e29 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3359,7 +3359,7 @@ char * virFileSanitizePath(const char *path) { const char *cur =3D path; - char *uri; + const char *uri; char *cleanpath; int idx =3D 0; =20 diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 031baa1407..22bda87643 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -119,8 +119,8 @@ virStorageFileGetNPIVKey(const char *path, char **key) { int status; - const char *serial; - const char *port; + char *serial; + char *port; g_autofree char *outbuf =3D NULL; g_autoptr(virCommand) cmd =3D NULL; =20 diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index c017ad34b7..b638fbd16c 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -219,7 +219,7 @@ static int virSysinfoParsePPCSystem(const char *base, virSysinfoSystemDef **sysdef) { int ret =3D -1; - char *eol =3D NULL; + const char *eol =3D NULL; const char *cur; virSysinfoSystemDef *def; =20 @@ -267,7 +267,7 @@ static void virSysinfoParsePPCProcessor(const char *base, virSysinfoDef *ret) { const char *cur; - char *eol, *tmp_base; + const char *eol, *tmp_base; virSysinfoProcessorDef *processor; =20 while ((tmp_base =3D strstr(base, "processor")) !=3D NULL) { @@ -336,7 +336,7 @@ static int virSysinfoParseARMSystem(const char *base, virSysinfoSystemDef **sysdef) { int ret =3D -1; - char *eol =3D NULL; + const char *eol =3D NULL; const char *cur; virSysinfoSystemDef *def; =20 @@ -384,7 +384,7 @@ static void virSysinfoParseARMProcessor(const char *base, virSysinfoDef *ret) { const char *cur; - char *eol, *tmp_base; + const char *eol, *tmp_base; virSysinfoProcessorDef *processor; char *processor_type =3D NULL; =20 diff --git a/src/util/virxml.c b/src/util/virxml.c index 77c7b5a8f4..274f072598 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -368,7 +368,8 @@ virXMLCheckIllegalChars(const char *nodeName, const char *str, const char *illegal) { - char *c; + const char *c; + if ((c =3D strpbrk(str, illegal))) { virReportError(VIR_ERR_XML_DETAIL, _("invalid char in %1$s: %2$c"), nodeName, *c); diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index a598b512dc..11db044b52 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -305,7 +305,7 @@ vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virD= omainDef *def) static int vmwareParsePath(const char *path, char **directory, char **filename) { - char *separator; + const char *separator; =20 separator =3D strrchr(path, '/'); =20 diff --git a/tools/vsh.c b/tools/vsh.c index 4aacc5feac..69d3930e43 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -413,7 +413,7 @@ vshCmddefCheckInternals(vshControl *ctl, case VSH_OT_ALIAS: { size_t j; g_autofree char *name =3D NULL; - char *p; + const char *p; =20 if (opt->required || opt->positional || @@ -502,7 +502,7 @@ vshCmdGetOption(vshControl *ctl, alias of option and its default value */ alias =3D g_strdup(n->def->help); name =3D alias; - if ((value =3D strchr(name, '=3D'))) { + if ((value =3D strchr(alias, '=3D'))) { *value =3D '\0'; if (*optstr) { if (report) @@ -1660,7 +1660,7 @@ vshCommandParse(vshControl *ctl, * value * -- (terminate accepting '--option', fill only positional = args) */ - const char *optionname =3D tkdata + 2; + char *optionname =3D tkdata + 2; char *sep; =20 if (!STRPREFIX(tkdata, "--")) { --=20 2.51.2