lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAP-5=fV+uJpppt3XLDqCdxmxCn3mGE9MoCbKgLJRuiLQ_745xA@mail.gmail.com>
Date: Wed, 21 Jan 2026 10:44:01 -0800
From: Ian Rogers <irogers@...gle.com>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: David Laight <david.laight.linux@...il.com>, Namhyung Kim <namhyung@...nel.org>, 
	Ingo Molnar <mingo@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, 
	James Clark <james.clark@...aro.org>, Jiri Olsa <jolsa@...nel.org>, 
	Adrian Hunter <adrian.hunter@...el.com>, Kan Liang <kan.liang@...ux.intel.com>, 
	Clark Williams <williams@...hat.com>, linux-kernel@...r.kernel.org, 
	linux-perf-users@...r.kernel.org, Arnaldo Carvalho de Melo <acme@...hat.com>
Subject: Re: [PATCH 3/4] perf list: Don't write to const memory

On Wed, Jan 21, 2026 at 10:40 AM Arnaldo Carvalho de Melo
<acme@...nel.org> wrote:
>
> On Wed, Jan 21, 2026 at 11:25:36AM +0000, David Laight wrote:
> > On Tue, 20 Jan 2026 19:08:59 -0300
> > Arnaldo Carvalho de Melo <acme@...nel.org> wrote:
> >
> > > From: Arnaldo Carvalho de Melo <acme@...hat.com>
> > >
> > > Something now detected on fedora 44, where strchr() returns const if it
> > > is passed a const pointer:
> > >
> > >   util/print-events.c: In function 'print_sdt_events':
> > >   util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> > >      89 |                 char *bid = strchr(sdt_name->s, '@');
> > >         |                             ^~~~~~
> > >
> > > Fix it by using strnchr() if strchr finds the separator instead of
> > > temporarily scrubbing it with '\0'.
> > >
> > > Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
> > > ---
> > >  tools/perf/util/print-events.c | 13 +++++--------
> > >  1 file changed, 5 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> > > index 8f3ed83853a9e468..898cf426509790cd 100644
> > > --- a/tools/perf/util/print-events.c
> > > +++ b/tools/perf/util/print-events.c
> > > @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> > >             } else {
> > >                     next_sdt_name = strlist__next(sdt_name);
> > >                     if (next_sdt_name) {
> > > -                           char *bid2 = strchr(next_sdt_name->s, '@');
> > > -
> > > -                           if (bid2)
> > > -                                   *bid2 = '\0';
> > > -                           if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> > > -                                   show_detail = true;
> > > -                           if (bid2)
> > > -                                   *bid2 = '@';
> > > +                           const char *bid2 = strchr(next_sdt_name->s, '@');
> > > +
> > > +                           show_detail = bid2 ?
> > > +                                           strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> > > +                                           strcmp(sdt_name->s, next_sdt_name->s) == 0;
> >
> > You could use:
> >       show_detail = strncmp(sdt_name->s, next_sdt_name->s, strcspn(sdt_name->s, "@"));
> > strcspn() will be slower, but it is succinct.
>
> That works.
>
> > I'm sure there is a function like strchr() that returns a pointer to the '\0'
> > when the character isn't found - but I can't remember what it is called :-(
>
> strchrnull()
>
> And this also works and I'll use it:
>
>                                 const char *bid2 = strchrnul(next_sdt_name->s, '@');
>
>                                 show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
>
> This way the patch ends up as below, thanks for the suggestion!
>
> Ian, I think I can keep your Reviewed-by, ok?

Yup.

Thanks,
Ian

> Cheers,
>
> - Arnaldo
>
> From 02b160f200a2224e8ecf490cf2e316b1a994509a Mon Sep 17 00:00:00 2001
> From: Arnaldo Carvalho de Melo <acme@...hat.com>
> Date: Tue, 20 Jan 2026 18:16:09 -0300
> Subject: [PATCH 1/1] perf list: Don't write to const memory
>
> Something now detected on fedora 44, where strchr() returns const if it
> is passed a const pointer:
>
>   util/print-events.c: In function 'print_sdt_events':
>   util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
>      89 |                 char *bid = strchr(sdt_name->s, '@');
>         |                             ^~~~~~
>
> Fix it by using strncnmp() + strchrnul() instead of temporarily
> scrubbing it with '\0'.
>
> Reviewed-by: Ian Rogers <irogers@...gle.com>
> Suggested-by: David Laight <david.laight.linux@...il.com>
> Link: https://lore.kernel.org/r/20260121112536.27fd5d11@pumpkin
> Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
> ---
>  tools/perf/util/print-events.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index 4bbcdbf05b843302..cb27e2898aa0558f 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -97,14 +97,9 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
>                 } else {
>                         next_sdt_name = strlist__next(sdt_name);
>                         if (next_sdt_name) {
> -                               char *bid2 = strchr(next_sdt_name->s, '@');
> -
> -                               if (bid2)
> -                                       *bid2 = '\0';
> -                               if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> -                                       show_detail = true;
> -                               if (bid2)
> -                                       *bid2 = '@';
> +                               const char *bid2 = strchrnul(next_sdt_name->s, '@');
> +
> +                               show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
>                         }
>                 }
>                 last_sdt_name = sdt_name->s;
> --
> 2.52.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ