Re: [PATCH v2 5/8] perf build-id: Change sprintf functions to snprintf

From: Arnaldo Carvalho de Melo
Date: Fri Apr 25 2025 - 11:09:52 EST


On Thu, Apr 24, 2025 at 12:58:28PM -0700, Ian Rogers wrote:
> Pass in a size argument rather than implying all build id strings must
> be SBUILD_ID_SIZE.
>
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> ---
> tools/perf/builtin-buildid-cache.c | 12 +++----
> tools/perf/builtin-buildid-list.c | 6 ++--
> tools/perf/util/build-id.c | 33 ++++++++-----------
> tools/perf/util/build-id.h | 6 ++--
> tools/perf/util/disasm.c | 2 +-
> tools/perf/util/dso.c | 4 +--
> tools/perf/util/dsos.c | 2 +-
> tools/perf/util/event.c | 2 +-
> tools/perf/util/header.c | 2 +-
> tools/perf/util/map.c | 2 +-
> tools/perf/util/probe-file.c | 4 +--
> .../scripting-engines/trace-event-python.c | 7 ++--
> tools/perf/util/symbol.c | 2 +-
> 13 files changed, 38 insertions(+), 46 deletions(-)

You missed these, that I added, please ack.

- Arnaldo

diff --git a/tools/perf/tests/sdt.c b/tools/perf/tests/sdt.c
index 9197128992510218..663c8f700069d42b 100644
--- a/tools/perf/tests/sdt.c
+++ b/tools/perf/tests/sdt.c
@@ -37,7 +37,7 @@ static int build_id_cache__add_file(const char *filename)
return err;
}

- build_id__sprintf(&bid, sbuild_id);
+ build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
err = build_id_cache__add_s(sbuild_id, filename, NULL, false, false);
if (err < 0)
pr_debug("Failed to add build id cache of %s\n", filename);
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 307ad6242a4e92f6..c10549fc451b508b 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -502,7 +502,7 @@ static struct debuginfo *open_from_debuginfod(struct dso *dso, struct nsinfo *ns
if (!c)
return NULL;

- build_id__sprintf(dso__bid(dso), sbuild_id);
+ build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
fd = debuginfod_find_debuginfo(c, (const unsigned char *)sbuild_id,
0, &path);
if (fd >= 0)
@@ -1089,7 +1089,7 @@ static int __show_line_range(struct line_range *lr, const char *module,
}
if (dinfo->build_id) {
build_id__init(&bid, dinfo->build_id, BUILD_ID_SIZE);
- build_id__sprintf(&bid, sbuild_id);
+ build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
}
debuginfo__delete(dinfo);
if (ret == 0 || ret == -ENOENT) {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 3cc7c40f50978a0f..b74f6fe24bb61af8 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -859,7 +859,7 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
comp_dir = cu_get_comp_dir(&pf->cu_die);
if (pf->dbg->build_id) {
build_id__init(&bid, pf->dbg->build_id, BUILD_ID_SIZE);
- build_id__sprintf(&bid, sbuild_id);
+ build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
}
ret = find_source_path(pf->fname, sbuild_id, comp_dir, &fpath);
if (ret < 0) {