Linux Perf Users
 help / color / mirror / Atom feed
* [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

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