Skip to content

Commit eee4b66

Browse files
captain5050namhyung
authored andcommitted
perf build-id: Ensure struct build_id is empty before use
If a build ID is read then not all code paths may ensure it is empty before use. Initialize the build_id to be zero-ed unless there is clear initialization such as a call to build_id__init. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 29be60c commit eee4b66

File tree

11 files changed

+20
-17
lines changed

11 files changed

+20
-17
lines changed

tools/perf/bench/inject-buildid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,
8080
int typeflag, struct FTW *ftwbuf __maybe_unused)
8181
{
8282
struct bench_dso *dso = &dsos[nr_dsos];
83-
struct build_id bid;
83+
struct build_id bid = { .size = 0, };
8484

8585
if (typeflag == FTW_D || typeflag == FTW_SL)
8686
return 0;

tools/perf/builtin-buildid-cache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
175175
static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
176176
{
177177
char sbuild_id[SBUILD_ID_SIZE];
178-
struct build_id bid;
178+
struct build_id bid = { .size = 0, };
179179
int err;
180180
struct nscookie nsc;
181181

@@ -198,7 +198,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
198198
static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)
199199
{
200200
char sbuild_id[SBUILD_ID_SIZE];
201-
struct build_id bid;
201+
struct build_id bid = { .size = 0, };
202202
struct nscookie nsc;
203203

204204
int err;
@@ -275,7 +275,7 @@ static int build_id_cache__purge_all(void)
275275
static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
276276
{
277277
char filename[PATH_MAX];
278-
struct build_id bid;
278+
struct build_id bid = { .size = 0, };
279279

280280
if (!dso__build_id_filename(dso, filename, sizeof(filename), false))
281281
return true;
@@ -303,7 +303,7 @@ static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *f
303303
static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
304304
{
305305
char sbuild_id[SBUILD_ID_SIZE];
306-
struct build_id bid;
306+
struct build_id bid = { .size = 0, };
307307
struct nscookie nsc;
308308

309309
int err;

tools/perf/tests/pe-file-parsing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int run_dir(const char *d)
2424
{
2525
char filename[PATH_MAX];
2626
char debugfile[PATH_MAX];
27-
struct build_id bid;
27+
struct build_id bid = { .size = 0, };
2828
char debuglink[PATH_MAX];
2929
char expect_build_id[] = {
3030
0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22,

tools/perf/tests/sdt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int target_function(void)
2828
static int build_id_cache__add_file(const char *filename)
2929
{
3030
char sbuild_id[SBUILD_ID_SIZE];
31-
struct build_id bid;
31+
struct build_id bid = { .size = 0, };
3232
int err;
3333

3434
err = filename__read_build_id(filename, &bid);

tools/perf/util/build-id.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int build_id__snprintf(const struct build_id *build_id, char *bf, size_t bf_size
9595
int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t sbuild_id_size)
9696
{
9797
char notes[PATH_MAX];
98-
struct build_id bid;
98+
struct build_id bid = { .size = 0, };
9999
int ret;
100100

101101
if (!root_dir)
@@ -112,7 +112,7 @@ int sysfs__snprintf_build_id(const char *root_dir, char *sbuild_id, size_t sbuil
112112

113113
int filename__snprintf_build_id(const char *pathname, char *sbuild_id, size_t sbuild_id_size)
114114
{
115-
struct build_id bid;
115+
struct build_id bid = { .size = 0, };
116116
int ret;
117117

118118
ret = filename__read_build_id(pathname, &bid);
@@ -849,7 +849,7 @@ static int filename__read_build_id_ns(const char *filename,
849849

850850
static bool dso__build_id_mismatch(struct dso *dso, const char *name)
851851
{
852-
struct build_id bid;
852+
struct build_id bid = { .size = 0, };
853853
bool ret = false;
854854

855855
mutex_lock(dso__lock(dso));

tools/perf/util/debuginfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct debuginfo *debuginfo__new(const char *path)
103103
char buf[PATH_MAX], nil = '\0';
104104
struct dso *dso;
105105
struct debuginfo *dinfo = NULL;
106-
struct build_id bid;
106+
struct build_id bid = { .size = 0};
107107

108108
/* Try to open distro debuginfo files */
109109
dso = dso__new(path);

tools/perf/util/probe-event.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,6 @@ static int sprint_line_description(char *sbuf, size_t size, struct line_range *l
10631063
static int __show_line_range(struct line_range *lr, const char *module,
10641064
bool user)
10651065
{
1066-
struct build_id bid;
10671066
int l = 1;
10681067
struct int_node *ln;
10691068
struct debuginfo *dinfo;
@@ -1088,6 +1087,8 @@ static int __show_line_range(struct line_range *lr, const char *module,
10881087
ret = -ENOENT;
10891088
}
10901089
if (dinfo->build_id) {
1090+
struct build_id bid;
1091+
10911092
build_id__init(&bid, dinfo->build_id, BUILD_ID_SIZE);
10921093
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
10931094
}

tools/perf/util/probe-finder.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,6 @@ static int probe_point_lazy_walker(const char *fname, int lineno,
848848
/* Find probe points from lazy pattern */
849849
static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
850850
{
851-
struct build_id bid;
852851
char sbuild_id[SBUILD_ID_SIZE] = "";
853852
int ret = 0;
854853
char *fpath;
@@ -858,6 +857,8 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
858857

859858
comp_dir = cu_get_comp_dir(&pf->cu_die);
860859
if (pf->dbg->build_id) {
860+
struct build_id bid;
861+
861862
build_id__init(&bid, pf->dbg->build_id, BUILD_ID_SIZE);
862863
build_id__snprintf(&bid, sbuild_id, sizeof(sbuild_id));
863864
}

tools/perf/util/symbol-minimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int dso__load_sym(struct dso *dso, struct map *map __maybe_unused,
317317
struct symsrc *runtime_ss __maybe_unused,
318318
int kmodule __maybe_unused)
319319
{
320-
struct build_id bid;
320+
struct build_id bid = { .size = 0, };
321321
int ret;
322322

323323
ret = fd__is_64_bit(ss->fd);

tools/perf/util/symbol.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,6 @@ int dso__load(struct dso *dso, struct map *map)
18131813
struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
18141814
bool kmod;
18151815
bool perfmap;
1816-
struct build_id bid;
18171816
struct nscookie nsc;
18181817
char newmapname[PATH_MAX];
18191818
const char *map_path = dso__long_name(dso);
@@ -1874,6 +1873,8 @@ int dso__load(struct dso *dso, struct map *map)
18741873
*/
18751874
if (!dso__has_build_id(dso) &&
18761875
is_regular_file(dso__long_name(dso))) {
1876+
struct build_id bid = { .size = 0, };
1877+
18771878
__symbol__join_symfs(name, PATH_MAX, dso__long_name(dso));
18781879
if (filename__read_build_id(name, &bid) > 0)
18791880
dso__set_build_id(dso, &bid);
@@ -2122,7 +2123,7 @@ static bool filename__readable(const char *file)
21222123

21232124
static char *dso__find_kallsyms(struct dso *dso, struct map *map)
21242125
{
2125-
struct build_id bid;
2126+
struct build_id bid = { .size = 0, };
21262127
char sbuild_id[SBUILD_ID_SIZE];
21272128
bool is_host = false;
21282129
char path[PATH_MAX];

0 commit comments

Comments
 (0)