* [PATCH] perf build-id: Fix off-by-one bug when printing kernel/module build-id
@ 2026-05-19 22:38 Michael Petlan
2026-05-20 15:55 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Michael Petlan @ 2026-05-19 22:38 UTC (permalink / raw)
To: linux-perf-users, irogers, namhyung
When changing sprintf functions to snprintf, one byte got lost. Since
snprintf ones do not handle the '\0' terminating character, the number
of printed characters is 40, while sizeof(sbuild_id) is 41, including
the terminating '\0' character. This makes the later check fail so that
nothing is printed.
Fix that.
Before:
[Michael@Carbon ~]$ perf buildid-list -k
[Michael@Carbon ~]$
After:
[Michael@Carbon ~]$ perf buildid-list -k
a527806324d543c4bc3ff2f9c9519d494fed5f68
[Michael@Carbon ~]$
Fixes: fccaaf6fbbc5 ("perf build-id: Change sprintf functions to snprintf")
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
tools/perf/builtin-buildid-list.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index a91bbb34ac94..e0881b0ac38f 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -61,7 +61,7 @@ static int sysfs__fprintf_build_id(FILE *fp)
int ret;
ret = sysfs__snprintf_build_id("/", sbuild_id, sizeof(sbuild_id));
- if (ret != sizeof(sbuild_id))
+ if (ret + 1 != sizeof(sbuild_id))
return ret < 0 ? ret : -EINVAL;
return fprintf(fp, "%s\n", sbuild_id);
@@ -73,7 +73,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)
int ret;
ret = filename__snprintf_build_id(name, sbuild_id, sizeof(sbuild_id));
- if (ret != sizeof(sbuild_id))
+ if (ret + 1 != sizeof(sbuild_id))
return ret < 0 ? ret : -EINVAL;
return fprintf(fp, "%s\n", sbuild_id);
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] perf build-id: Fix off-by-one bug when printing kernel/module build-id
2026-05-19 22:38 [PATCH] perf build-id: Fix off-by-one bug when printing kernel/module build-id Michael Petlan
@ 2026-05-20 15:55 ` Ian Rogers
2026-05-20 18:51 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2026-05-20 15:55 UTC (permalink / raw)
To: Michael Petlan; +Cc: linux-perf-users, namhyung
On Tue, May 19, 2026 at 3:39 PM Michael Petlan <mpetlan@redhat.com> wrote:
>
> When changing sprintf functions to snprintf, one byte got lost. Since
> snprintf ones do not handle the '\0' terminating character, the number
> of printed characters is 40, while sizeof(sbuild_id) is 41, including
> the terminating '\0' character. This makes the later check fail so that
> nothing is printed.
>
> Fix that.
>
> Before:
> [Michael@Carbon ~]$ perf buildid-list -k
> [Michael@Carbon ~]$
>
> After:
> [Michael@Carbon ~]$ perf buildid-list -k
> a527806324d543c4bc3ff2f9c9519d494fed5f68
> [Michael@Carbon ~]$
>
> Fixes: fccaaf6fbbc5 ("perf build-id: Change sprintf functions to snprintf")
>
> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Tested-by: Ian Rogers <irogers@google.com>
also Sashiko is green for this patch:
https://sashiko.dev/#/patchset/20260519223855.191637-1-mpetlan%40redhat.com
Thanks!
Ian
> ---
> tools/perf/builtin-buildid-list.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
> index a91bbb34ac94..e0881b0ac38f 100644
> --- a/tools/perf/builtin-buildid-list.c
> +++ b/tools/perf/builtin-buildid-list.c
> @@ -61,7 +61,7 @@ static int sysfs__fprintf_build_id(FILE *fp)
> int ret;
>
> ret = sysfs__snprintf_build_id("/", sbuild_id, sizeof(sbuild_id));
> - if (ret != sizeof(sbuild_id))
> + if (ret + 1 != sizeof(sbuild_id))
> return ret < 0 ? ret : -EINVAL;
>
> return fprintf(fp, "%s\n", sbuild_id);
> @@ -73,7 +73,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)
> int ret;
>
> ret = filename__snprintf_build_id(name, sbuild_id, sizeof(sbuild_id));
> - if (ret != sizeof(sbuild_id))
> + if (ret + 1 != sizeof(sbuild_id))
> return ret < 0 ? ret : -EINVAL;
>
> return fprintf(fp, "%s\n", sbuild_id);
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf build-id: Fix off-by-one bug when printing kernel/module build-id
2026-05-20 15:55 ` Ian Rogers
@ 2026-05-20 18:51 ` Arnaldo Carvalho de Melo
2026-05-20 23:00 ` Namhyung Kim
0 siblings, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-05-20 18:51 UTC (permalink / raw)
To: Ian Rogers; +Cc: Michael Petlan, linux-perf-users, namhyung
On Wed, May 20, 2026 at 08:55:51AM -0700, Ian Rogers wrote:
> On Tue, May 19, 2026 at 3:39 PM Michael Petlan <mpetlan@redhat.com> wrote:
> >
> > When changing sprintf functions to snprintf, one byte got lost. Since
> > snprintf ones do not handle the '\0' terminating character, the number
> > of printed characters is 40, while sizeof(sbuild_id) is 41, including
> > the terminating '\0' character. This makes the later check fail so that
> > nothing is printed.
> >
> > Fix that.
> >
> > Before:
> > [Michael@Carbon ~]$ perf buildid-list -k
> > [Michael@Carbon ~]$
> >
> > After:
> > [Michael@Carbon ~]$ perf buildid-list -k
> > a527806324d543c4bc3ff2f9c9519d494fed5f68
> > [Michael@Carbon ~]$
> >
> > Fixes: fccaaf6fbbc5 ("perf build-id: Change sprintf functions to snprintf")
> >
> > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
>
> Tested-by: Ian Rogers <irogers@google.com>
> also Sashiko is green for this patch:
> https://sashiko.dev/#/patchset/20260519223855.191637-1-mpetlan%40redhat.com
Thanks, applied to perf-tools-next, for v7.2.
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf build-id: Fix off-by-one bug when printing kernel/module build-id
2026-05-20 18:51 ` Arnaldo Carvalho de Melo
@ 2026-05-20 23:00 ` Namhyung Kim
0 siblings, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2026-05-20 23:00 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: Ian Rogers, Michael Petlan, linux-perf-users
On Wed, May 20, 2026 at 03:51:12PM -0300, Arnaldo Carvalho de Melo wrote:
> On Wed, May 20, 2026 at 08:55:51AM -0700, Ian Rogers wrote:
> > On Tue, May 19, 2026 at 3:39 PM Michael Petlan <mpetlan@redhat.com> wrote:
> > >
> > > When changing sprintf functions to snprintf, one byte got lost. Since
> > > snprintf ones do not handle the '\0' terminating character, the number
> > > of printed characters is 40, while sizeof(sbuild_id) is 41, including
> > > the terminating '\0' character. This makes the later check fail so that
> > > nothing is printed.
> > >
> > > Fix that.
> > >
> > > Before:
> > > [Michael@Carbon ~]$ perf buildid-list -k
> > > [Michael@Carbon ~]$
> > >
> > > After:
> > > [Michael@Carbon ~]$ perf buildid-list -k
> > > a527806324d543c4bc3ff2f9c9519d494fed5f68
> > > [Michael@Carbon ~]$
> > >
> > > Fixes: fccaaf6fbbc5 ("perf build-id: Change sprintf functions to snprintf")
> > >
> > > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> >
> > Tested-by: Ian Rogers <irogers@google.com>
> > also Sashiko is green for this patch:
> > https://sashiko.dev/#/patchset/20260519223855.191637-1-mpetlan%40redhat.com
>
> Thanks, applied to perf-tools-next, for v7.2.
I sent out this a month ago, but forgot to ping for inclusion.
https://lore.kernel.org/linux-perf-users/20260420180858.129075-1-namhyung@kernel.org/
Anyway, I'm ok with fixing it either way.
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-20 23:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 22:38 [PATCH] perf build-id: Fix off-by-one bug when printing kernel/module build-id Michael Petlan
2026-05-20 15:55 ` Ian Rogers
2026-05-20 18:51 ` Arnaldo Carvalho de Melo
2026-05-20 23:00 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox