Check for switch offset validity in the MethodAnalyzer

This commit is contained in:
Ben Gruver 2016-02-14 19:08:19 -08:00
parent 6429b3daa9
commit 5b2943d89b

View File

@ -499,11 +499,19 @@ public class MethodAnalyzer {
OffsetInstruction offsetInstruction = (OffsetInstruction)instruction.instruction;
if (instructionOpcode == Opcode.PACKED_SWITCH || instructionOpcode == Opcode.SPARSE_SWITCH) {
SwitchPayload switchPayload = (SwitchPayload)analyzedInstructions.get(instructionCodeAddress +
offsetInstruction.getCodeOffset()).instruction;
AnalyzedInstruction analyzedSwitchPayload = analyzedInstructions.get(
instructionCodeAddress + offsetInstruction.getCodeOffset());
if (analyzedSwitchPayload == null) {
throw new AnalysisException("Invalid switch payload offset");
}
SwitchPayload switchPayload = (SwitchPayload)analyzedSwitchPayload.instruction;
for (SwitchElement switchElement: switchPayload.getSwitchElements()) {
AnalyzedInstruction targetInstruction = analyzedInstructions.get(instructionCodeAddress +
switchElement.getOffset());
if (targetInstruction == null) {
throw new AnalysisException("Invalid switch target offset");
}
addPredecessorSuccessor(instruction, targetInstruction, exceptionHandlers,
instructionsToProcess);