perf buildid-cache: Fix use of uninitialized value
authorIan Rogers <irogers@google.com>
Mon, 9 Oct 2023 18:39:07 +0000 (11:39 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 12 Oct 2023 17:01:56 +0000 (10:01 -0700)
The buildid filename is first determined and then from this the
buildid read. If getting the filename fails then the buildid will be
used for a later memcmp uninitialized. Detected by clang-tidy.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: llvm@lists.linux.dev
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Tom Rix <trix@redhat.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20231009183920.200859-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-buildid-cache.c

index cd381693658bc9c1371e35a109950d79ef1b8bd5..e2a40f1d9225a538085ad8b07c18e85aa62d9505 100644 (file)
@@ -277,8 +277,10 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
        char filename[PATH_MAX];
        struct build_id bid;
 
-       if (dso__build_id_filename(dso, filename, sizeof(filename), false) &&
-           filename__read_build_id(filename, &bid) == -1) {
+       if (!dso__build_id_filename(dso, filename, sizeof(filename), false))
+               return true;
+
+       if (filename__read_build_id(filename, &bid) == -1) {
                if (errno == ENOENT)
                        return false;