mirror of https://github.com/torvalds/linux.git
perf build-id: Change sprintf functions to snprintf
Pass in a size argument rather than implying all build id strings must be SBUILD_ID_SIZE. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20250724163302.596743-4-irogers@google.com [ fixed some build errors ] Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
5a2ceebd81
commit
fccaaf6fbb
|
|
@ -31,7 +31,7 @@
|
|||
#include <linux/string.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
|
||||
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid, size_t sbuildid_size)
|
||||
{
|
||||
char root_dir[PATH_MAX];
|
||||
char *p;
|
||||
|
|
@ -42,7 +42,7 @@ static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
|
|||
if (!p)
|
||||
return -1;
|
||||
*p = '\0';
|
||||
return sysfs__sprintf_build_id(root_dir, sbuildid);
|
||||
return sysfs__snprintf_build_id(root_dir, sbuildid, sbuildid_size);
|
||||
}
|
||||
|
||||
static int build_id_cache__kcore_dir(char *dir, size_t sz)
|
||||
|
|
@ -128,7 +128,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
|
|||
return -1;
|
||||
*p = '\0';
|
||||
|
||||
if (build_id_cache__kcore_buildid(from_dir, sbuildid) < 0)
|
||||
if (build_id_cache__kcore_buildid(from_dir, sbuildid, sizeof(sbuildid)) < 0)
|
||||
return -1;
|
||||
|
||||
scnprintf(to_dir, sizeof(to_dir), "%s/%s/%s",
|
||||
|
|
@ -187,7 +187,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
|
|||
return -1;
|
||||
}
|
||||
|
||||
build_id__sprintf(&bid, sbuild_id);
|
||||
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
|
||||
err = build_id_cache__add_s(sbuild_id, filename, nsi,
|
||||
false, false);
|
||||
pr_debug("Adding %s %s: %s\n", sbuild_id, filename,
|
||||
|
|
@ -211,7 +211,7 @@ static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)
|
|||
return -1;
|
||||
}
|
||||
|
||||
build_id__sprintf(&bid, sbuild_id);
|
||||
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
|
||||
err = build_id_cache__remove_s(sbuild_id);
|
||||
pr_debug("Removing %s %s: %s\n", sbuild_id, filename,
|
||||
err ? "FAIL" : "Ok");
|
||||
|
|
@ -317,7 +317,7 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
|
|||
}
|
||||
err = 0;
|
||||
|
||||
build_id__sprintf(&bid, sbuild_id);
|
||||
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
|
||||
if (build_id_cache__cached(sbuild_id))
|
||||
err = build_id_cache__remove_s(sbuild_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)
|
|||
|
||||
memset(bid_buf, 0, sizeof(bid_buf));
|
||||
if (dso__has_build_id(dso))
|
||||
build_id__sprintf(dso__bid_const(dso), bid_buf);
|
||||
build_id__snprintf(dso__bid_const(dso), bid_buf, sizeof(bid_buf));
|
||||
printf("%s %16" PRIx64 " %16" PRIx64, bid_buf, map__start(map), map__end(map));
|
||||
if (dso_long_name != NULL)
|
||||
printf(" %s", dso_long_name);
|
||||
|
|
@ -57,7 +57,7 @@ static int sysfs__fprintf_build_id(FILE *fp)
|
|||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
int ret;
|
||||
|
||||
ret = sysfs__sprintf_build_id("/", sbuild_id);
|
||||
ret = sysfs__snprintf_build_id("/", sbuild_id, sizeof(sbuild_id));
|
||||
if (ret != sizeof(sbuild_id))
|
||||
return ret < 0 ? ret : -EINVAL;
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)
|
|||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
int ret;
|
||||
|
||||
ret = filename__sprintf_build_id(name, sbuild_id);
|
||||
ret = filename__snprintf_build_id(name, sbuild_id, sizeof(sbuild_id));
|
||||
if (ret != sizeof(sbuild_id))
|
||||
return ret < 0 ? ret : -EINVAL;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -67,24 +67,17 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int build_id__sprintf(const struct build_id *build_id, char *bf)
|
||||
int build_id__snprintf(const struct build_id *build_id, char *bf, size_t bf_size)
|
||||
{
|
||||
char *bid = bf;
|
||||
const u8 *raw = build_id->data;
|
||||
size_t i;
|
||||
size_t offs = 0;
|
||||
|
||||
bf[0] = 0x0;
|
||||
for (size_t i = 0; i < build_id->size && offs < bf_size; ++i)
|
||||
offs += snprintf(bf + offs, bf_size - offs, "%02x", build_id->data[i]);
|
||||
|
||||
for (i = 0; i < build_id->size; ++i) {
|
||||
sprintf(bid, "%02x", *raw);
|
||||
++raw;
|
||||
bid += 2;
|
||||
}
|
||||
|
||||
return (bid - bf) + 1;
|
||||
return offs;
|
||||
}
|
||||
|
||||
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
|
||||
int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t sbuild_id_size)
|
||||
{
|
||||
char notes[PATH_MAX];
|
||||
struct build_id bid;
|
||||
|
|
@ -99,10 +92,10 @@ int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return build_id__sprintf(&bid, sbuild_id);
|
||||
return build_id__snprintf(&bid, sbuild_id, sbuild_id_size);
|
||||
}
|
||||
|
||||
int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
|
||||
int filename__snprintf_build_id(const char *pathname, char *sbuild_id, size_t sbuild_id_size)
|
||||
{
|
||||
struct build_id bid;
|
||||
int ret;
|
||||
|
|
@ -111,7 +104,7 @@ int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return build_id__sprintf(&bid, sbuild_id);
|
||||
return build_id__snprintf(&bid, sbuild_id, sbuild_id_size);
|
||||
}
|
||||
|
||||
/* asnprintf consolidates asprintf and snprintf */
|
||||
|
|
@ -212,9 +205,9 @@ static bool build_id_cache__valid_id(char *sbuild_id)
|
|||
return false;
|
||||
|
||||
if (!strcmp(pathname, DSO__NAME_KALLSYMS))
|
||||
ret = sysfs__sprintf_build_id("/", real_sbuild_id);
|
||||
ret = sysfs__snprintf_build_id("/", real_sbuild_id, sizeof(real_sbuild_id));
|
||||
else if (pathname[0] == '/')
|
||||
ret = filename__sprintf_build_id(pathname, real_sbuild_id);
|
||||
ret = filename__snprintf_build_id(pathname, real_sbuild_id, sizeof(real_sbuild_id));
|
||||
else
|
||||
ret = -EINVAL; /* Should we support other special DSO cache? */
|
||||
if (ret >= 0)
|
||||
|
|
@ -243,7 +236,7 @@ char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t size,
|
|||
if (!dso__has_build_id(dso))
|
||||
return NULL;
|
||||
|
||||
build_id__sprintf(dso__bid_const(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid_const(dso), sbuild_id, sizeof(sbuild_id));
|
||||
linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
|
||||
if (!linkname)
|
||||
return NULL;
|
||||
|
|
@ -769,7 +762,7 @@ static int build_id_cache__add_b(const struct build_id *bid,
|
|||
{
|
||||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
|
||||
build_id__sprintf(bid, sbuild_id);
|
||||
build_id__snprintf(bid, sbuild_id, sizeof(sbuild_id));
|
||||
|
||||
return __build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms,
|
||||
is_vdso, proper_name, root_dir);
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ struct feat_fd;
|
|||
struct nsinfo;
|
||||
|
||||
void build_id__init(struct build_id *bid, const u8 *data, size_t size);
|
||||
int build_id__sprintf(const struct build_id *build_id, char *bf);
|
||||
int build_id__snprintf(const struct build_id *build_id, char *bf, size_t bf_size);
|
||||
bool build_id__is_defined(const struct build_id *bid);
|
||||
int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id);
|
||||
int filename__sprintf_build_id(const char *pathname, char *sbuild_id);
|
||||
int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t sbuild_id_size);
|
||||
int filename__snprintf_build_id(const char *pathname, char *sbuild_id, size_t sbuild_id_size);
|
||||
char *build_id_cache__kallsyms_path(const char *sbuild_id, char *bf,
|
||||
size_t size);
|
||||
|
||||
|
|
|
|||
|
|
@ -1218,7 +1218,7 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, s
|
|||
char *build_id_msg = NULL;
|
||||
|
||||
if (dso__has_build_id(dso)) {
|
||||
build_id__sprintf(dso__bid(dso), bf + 15);
|
||||
build_id__snprintf(dso__bid(dso), bf + 15, sizeof(bf) - 15);
|
||||
build_id_msg = bf;
|
||||
}
|
||||
scnprintf(buf, buflen,
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
|
|||
break;
|
||||
}
|
||||
|
||||
build_id__sprintf(dso__bid_const(dso), build_id_hex);
|
||||
build_id__snprintf(dso__bid_const(dso), build_id_hex, sizeof(build_id_hex));
|
||||
len = __symbol__join_symfs(filename, size, "/usr/lib/debug/.build-id/");
|
||||
snprintf(filename + len, size - len, "%.2s/%s.debug",
|
||||
build_id_hex, build_id_hex + 2);
|
||||
|
|
@ -1708,7 +1708,7 @@ static size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
|
|||
{
|
||||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
return fprintf(fp, "%s", sbuild_id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ static int dsos__fprintf_buildid_cb(struct dso *dso, void *data)
|
|||
|
||||
if (args->skip && args->skip(dso, args->parm))
|
||||
return 0;
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
args->ret += fprintf(args->fp, "%-40s %s\n", sbuild_id, dso__long_name(dso));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)
|
|||
|
||||
build_id__init(&bid, event->mmap2.build_id,
|
||||
event->mmap2.build_id_size);
|
||||
build_id__sprintf(&bid, sbuild_id);
|
||||
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
|
||||
|
||||
return fprintf(fp, " %d/%d: [%#" PRI_lx64 "(%#" PRI_lx64 ") @ %#" PRI_lx64
|
||||
" <%s>]: %c%c%c%c %s\n",
|
||||
|
|
|
|||
|
|
@ -2303,7 +2303,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,
|
|||
free(m.name);
|
||||
}
|
||||
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
pr_debug("build id event received for %s: %s [%zu]\n",
|
||||
dso__long_name(dso), sbuild_id, size);
|
||||
dso__put(dso);
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ int map__load(struct map *map)
|
|||
if (dso__has_build_id(dso)) {
|
||||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
pr_debug("%s with build id %s not found", name, sbuild_id);
|
||||
} else
|
||||
pr_debug("Failed to open %s", name);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -448,10 +448,10 @@ static int probe_cache__open(struct probe_cache *pcache, const char *target,
|
|||
if (!target || !strcmp(target, DSO__NAME_KALLSYMS)) {
|
||||
target = DSO__NAME_KALLSYMS;
|
||||
is_kallsyms = true;
|
||||
ret = sysfs__sprintf_build_id("/", sbuildid);
|
||||
ret = sysfs__snprintf_build_id("/", sbuildid, sizeof(sbuildid));
|
||||
} else {
|
||||
nsinfo__mountns_enter(nsi, &nsc);
|
||||
ret = filename__sprintf_build_id(target, sbuildid);
|
||||
ret = filename__snprintf_build_id(target, sbuildid, sizeof(sbuildid));
|
||||
nsinfo__mountns_exit(&nsc);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -780,14 +780,13 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
|
|||
const char *sym_field, const char *symoff_field,
|
||||
const char *map_pgoff)
|
||||
{
|
||||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
|
||||
if (al->map) {
|
||||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
struct dso *dso = map__dso(al->map);
|
||||
|
||||
pydict_set_item_string_decref(dict, dso_field,
|
||||
_PyUnicode_FromString(dso__name(dso)));
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
pydict_set_item_string_decref(dict, dso_bid_field,
|
||||
_PyUnicode_FromString(sbuild_id));
|
||||
pydict_set_item_string_decref(dict, dso_map_start,
|
||||
|
|
@ -1238,7 +1237,7 @@ static int python_export_dso(struct db_export *dbe, struct dso *dso,
|
|||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
PyObject *t;
|
||||
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
|
||||
t = tuple_new(5);
|
||||
|
||||
|
|
|
|||
|
|
@ -2152,7 +2152,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
|
|||
goto proc_kallsyms;
|
||||
}
|
||||
|
||||
build_id__sprintf(dso__bid(dso), sbuild_id);
|
||||
build_id__snprintf(dso__bid(dso), sbuild_id, sizeof(sbuild_id));
|
||||
|
||||
/* Find kallsyms in build-id cache with kcore */
|
||||
scnprintf(path, sizeof(path), "%s/%s/%s",
|
||||
|
|
|
|||
Loading…
Reference in New Issue