summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2017-10-24 07:16:40 +0000
committerMartin Storsjo <martin@martin.st>2017-10-24 07:16:40 +0000
commit40a2e1e338ee856e16859e70c9b6f286902626b1 (patch)
treedbddd1bab2fb83573fda9af4ee4293212d9c4a06
parent12339e4916d3d1c42feea87a95ecbdfcdbbbc8ad (diff)
downloadlibunwind_llvm-40a2e1e338ee856e16859e70c9b6f286902626b1.tar.gz
Add missing checks for register number
Most other cases that touch savedRegisters[reg] have got this check, but these three seemed to lack it. Differential Revision: https://reviews.llvm.org/D39206 git-svn-id: https://llvm.org/svn/llvm-project/libunwind/trunk@316415 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--src/DwarfParser.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/DwarfParser.hpp b/src/DwarfParser.hpp
index 3c98d30..d45ad49 100644
--- a/src/DwarfParser.hpp
+++ b/src/DwarfParser.hpp
@@ -605,6 +605,13 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions,
break;
case DW_CFA_val_offset:
reg = addressSpace.getULEB128(p, instructionsEnd);
+ if (reg > kMaxRegisterNumber) {
+ fprintf(stderr,
+ "malformed DW_CFA_val_offset DWARF unwind, reg (%" PRIu64
+ ") out of range\n",
+ reg);
+ return false;
+ }
offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd)
* cieInfo.dataAlignFactor;
results->savedRegisters[reg].location = kRegisterOffsetFromCFA;
@@ -668,6 +675,12 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions,
switch (opcode & 0xC0) {
case DW_CFA_offset:
reg = operand;
+ if (reg > kMaxRegisterNumber) {
+ fprintf(stderr, "malformed DW_CFA_offset DWARF unwind, reg (%" PRIu64
+ ") out of range\n",
+ reg);
+ return false;
+ }
offset = (int64_t)addressSpace.getULEB128(p, instructionsEnd)
* cieInfo.dataAlignFactor;
results->savedRegisters[reg].location = kRegisterInCFA;
@@ -682,6 +695,12 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions,
break;
case DW_CFA_restore:
reg = operand;
+ if (reg > kMaxRegisterNumber) {
+ fprintf(stderr, "malformed DW_CFA_restore DWARF unwind, reg (%" PRIu64
+ ") out of range\n",
+ reg);
+ return false;
+ }
results->savedRegisters[reg] = initialState.savedRegisters[reg];
_LIBUNWIND_TRACE_DWARF("DW_CFA_restore(reg=%" PRIu64 ")\n",
static_cast<uint64_t>(operand));