aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-dwp/llvm-dwp.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2020-03-20 23:10:05 +0700
committerIgor Kudrin <ikudrin@accesssoftek.com>2020-04-06 14:31:00 +0700
commit5125685e915afe4d12961f5b3394918d04d49783 (patch)
tree4babee9d01d5d445777e047b3dcf155d0c20bce0 /llvm/tools/llvm-dwp/llvm-dwp.cpp
parent0570de73c4822b6b0da4758eefca2a36f01c7445 (diff)
downloadllvm-5125685e915afe4d12961f5b3394918d04d49783.zip
llvm-5125685e915afe4d12961f5b3394918d04d49783.tar.gz
llvm-5125685e915afe4d12961f5b3394918d04d49783.tar.bz2
[llvm-dwp] Fix a possible out of bound access.
llvm-dwp did not check section identifiers read from input files. In the case of an unexpected identifier, the calculated index for Contributions[] pointed outside the array. This fix avoids the issue by skipping unsupported identifiers. Differential Revision: https://reviews.llvm.org/D76543
Diffstat (limited to 'llvm/tools/llvm-dwp/llvm-dwp.cpp')
-rw-r--r--llvm/tools/llvm-dwp/llvm-dwp.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp
index 18cd92f..bcc5f38 100644
--- a/llvm/tools/llvm-dwp/llvm-dwp.cpp
+++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp
@@ -216,6 +216,10 @@ struct UnitIndexEntry {
StringRef DWPName;
};
+static bool isSupportedSectionKind(DWARFSectionKind Kind) {
+ return Kind != DW_SECT_EXT_unknown;
+}
+
// Convert an internal section identifier into the index to use with
// UnitIndexEntry::Contributions.
static unsigned getContributionIndex(DWARFSectionKind Kind) {
@@ -255,6 +259,8 @@ static void addAllTypesFromDWP(
// Zero out the debug_info contribution
Entry.Contributions[0] = {};
for (auto Kind : TUIndex.getColumnKinds()) {
+ if (!isSupportedSectionKind(Kind))
+ continue;
auto &C = Entry.Contributions[getContributionIndex(Kind)];
C.Offset += I->Offset;
C.Length = I->Length;
@@ -633,6 +639,8 @@ static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
NewEntry.DWOName = ID.DWOName;
NewEntry.DWPName = Input;
for (auto Kind : CUIndex.getColumnKinds()) {
+ if (!isSupportedSectionKind(Kind))
+ continue;
auto &C = NewEntry.Contributions[getContributionIndex(Kind)];
C.Offset += I->Offset;
C.Length = I->Length;