Skip to content

Commit

Permalink
Add missing checks for register number
Browse files Browse the repository at this point in the history
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

llvm-svn: 316415
  • Loading branch information
mstorsjo committed Oct 24, 2017
1 parent 2555e41 commit d3abd15
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libunwind/src/DwarfParser.hpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit d3abd15

Please sign in to comment.