Commit eee4b661 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

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: default avatarIan Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-6-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent 29be60c9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,
		   int typeflag, struct FTW *ftwbuf __maybe_unused)
{
	struct bench_dso *dso = &dsos[nr_dsos];
	struct build_id bid;
	struct build_id bid = { .size = 0, };

	if (typeflag == FTW_D || typeflag == FTW_SL)
		return 0;
+4 −4
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
{
	char sbuild_id[SBUILD_ID_SIZE];
	struct build_id bid;
	struct build_id bid = { .size = 0, };
	int err;
	struct nscookie nsc;

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

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

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

	int err;
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ static int run_dir(const char *d)
{
	char filename[PATH_MAX];
	char debugfile[PATH_MAX];
	struct build_id bid;
	struct build_id bid = { .size = 0, };
	char debuglink[PATH_MAX];
	char expect_build_id[] = {
		0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22,
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ static int target_function(void)
static int build_id_cache__add_file(const char *filename)
{
	char sbuild_id[SBUILD_ID_SIZE];
	struct build_id bid;
	struct build_id bid = { .size = 0, };
	int err;

	err = filename__read_build_id(filename, &bid);
+3 −3
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ int build_id__snprintf(const struct build_id *build_id, char *bf, size_t bf_size
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;
	struct build_id bid = { .size = 0, };
	int ret;

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

int filename__snprintf_build_id(const char *pathname, char *sbuild_id, size_t sbuild_id_size)
{
	struct build_id bid;
	struct build_id bid = { .size = 0, };
	int ret;

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

static bool dso__build_id_mismatch(struct dso *dso, const char *name)
{
	struct build_id bid;
	struct build_id bid = { .size = 0, };
	bool ret = false;

	mutex_lock(dso__lock(dso));
Loading