qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: [PATCH v2] log: Fix result of strstr to 'const char *'
Date: Tue, 9 Dec 2025 17:38:53 +0100	[thread overview]
Message-ID: <3b34f492-874a-4ec6-b973-38f72c09a3f4@redhat.com> (raw)
In-Reply-To: <20251209154128.661390-1-clg@redhat.com>

On 12/9/25 16:41, Cédric Le Goater wrote:
> Assigning the result of strstr() to a 'char *' is unsafe since
> strstr() returns a pointer into the original string which is a
> read-only 'const char *' string.
> 
> A recent change in glibc 2.42.9000  :
> 
>     https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690
> 
> breaks compiles, complaining the result of strstr() is not a
> 'const char *' :
> 
> ../util/log.c:208:24: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
>    208 |         char *pidstr = strstr(filename, "%");
>        |                        ^~~~~~

There is much more to fix ... :/

../backends/tpm/tpm_passthrough.c: In function ‘tpm_passthrough_open_sysfs_cancel’:
../backends/tpm/tpm_passthrough.c:226:9: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   226 |     dev = strrchr(tpm_pt->tpm_dev, '/');
--
../tests/vhost-user-bridge.c: In function ‘vubr_parse_host_port’:
../tests/vhost-user-bridge.c:749:15: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   749 |     char *p = strchr(buf, ':');
--
../ui/ui-hmp-cmds.c: In function ‘sendkey_completion’:
../ui/ui-hmp-cmds.c:427:9: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   427 |     sep = strrchr(str, '-');
--
../monitor/hmp.c: In function ‘key_get_info’:
../monitor/hmp.c:589:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   589 |     p = strchr(type, ':');
--
../qga/commands-linux.c: In function ‘build_guest_fsinfo_for_pci_dev’:
../qga/commands-linux.c:409:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   409 |     p = strstr(syspath, "/devices/pci");
       |       ^
../qga/commands-linux.c:440:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   440 |     p = strstr(syspath, "/target");
       |       ^
../qga/commands-linux.c:446:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   446 |     p = strstr(syspath, "/ata");
       |       ^
../qga/commands-linux.c:451:11: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   451 |         p = strstr(syspath, "/host");
--
../qga/commands-linux.c: In function ‘build_guest_fsinfo_for_nonpci_virtio’:
../qga/commands-linux.c:553:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   553 |     p = strstr(syspath, "/target");
--
../qga/commands-linux.c: In function ‘build_guest_fsinfo_for_ccw_dev’:
../qga/commands-linux.c:580:7: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   580 |     p = strstr(syspath, "/devices/css");
--
../gdbstub/gdbstub.c: In function ‘get_feature_xml’:
../gdbstub/gdbstub.c:365:18: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
   365 |     char *term = strchr(p, ':');
--
../block/vmdk.c: In function ‘vmdk_parse_description’:
../block/vmdk.c:1095:13: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
  1095 |     opt_pos = strstr(desc, opt_name);
--
../block/vvfat.c: In function ‘get_basename’:
../block/vvfat.c:1829:22: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
  1829 |     char* basename = strrchr(path, '/');





      reply	other threads:[~2025-12-09 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09 15:41 [PATCH v2] log: Fix result of strstr to 'const char *' Cédric Le Goater
2025-12-09 16:38 ` Cédric Le Goater [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b34f492-874a-4ec6-b973-38f72c09a3f4@redhat.com \
    --to=clg@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).