[llvm] [llvm-objdump][ELF]Add Shdr check for getBuildID(#126418) (PR #126537)
Ruoyu Qiu via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 08:35:43 PST 2025
https://github.com/cabbaken updated https://github.com/llvm/llvm-project/pull/126537
>From a19e1a05cde04298aee6732811353d1814d21eb8 Mon Sep 17 00:00:00 2001
From: Ruoyu Qiu <cabbaken at outlook.com>
Date: Mon, 10 Feb 2025 15:56:31 +0000
Subject: [PATCH] [llvm-objdump][ELF]Add Shdr buildID check(#126418)
Add Section Header check for getBuildID, fix crash
with invalid Program Header.
Signed-off-by: Ruoyu Qiu <cabbaken at outlook.com>
---
llvm/lib/Object/BuildID.cpp | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/llvm/lib/Object/BuildID.cpp b/llvm/lib/Object/BuildID.cpp
index 89d6bc3ab550db8..d44605712982725 100644
--- a/llvm/lib/Object/BuildID.cpp
+++ b/llvm/lib/Object/BuildID.cpp
@@ -24,6 +24,20 @@ using namespace llvm::object;
namespace {
template <typename ELFT> BuildIDRef getBuildID(const ELFFile<ELFT> &Obj) {
+ auto Sections = cantFail(Obj.sections());
+ if (!Sections.empty()) {
+ for (const auto &S : Sections) {
+ if (S.sh_type != ELF::SHT_NOTE)
+ continue;
+ Error Err = Error::success();
+ for (auto N : Obj.notes(S, Err))
+ if (N.getType() == ELF::NT_GNU_BUILD_ID &&
+ N.getName() == ELF::ELF_NOTE_GNU)
+ return N.getDesc(S.sh_addralign);
+ consumeError(std::move(Err));
+ }
+ }
+
auto PhdrsOrErr = Obj.program_headers();
if (!PhdrsOrErr) {
consumeError(PhdrsOrErr.takeError());
More information about the llvm-commits
mailing list