]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf build-id: Fix off-by-one bug when printing kernel/module build-id
authorMichael Petlan <mpetlan@redhat.com>
Tue, 19 May 2026 22:38:55 +0000 (00:38 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 May 2026 18:50:32 +0000 (15:50 -0300)
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: fccaaf6fbbc59910 ("perf build-id: Change sprintf functions to snprintf")
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Tested-by: Ian Rogers <irogers@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-buildid-list.c

index a91bbb34ac9463607de2e4c978a2c53d0112d68b..e0881b0ac38ff25a786108de6e42c4e30a47f785 100644 (file)
@@ -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);