Skip to content

Commit

Permalink
fix: Missing type narrowing check for *STORE operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Nov 29, 2020
1 parent 20f3e8c commit 4fa201e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ SimAnalzer analyzer = new SimAnalyzer(new SimInterpreter()) {
// Allow better type checking, default uses system classpath
return super.createTypeChecker();
}

@Override
protected ParameterFactory createParameterFactory() {
// Allow the interpreter to be fed literal values for the parameters of the analyzed method
return super.createParameterFactory();
}
};
// Determine if we want to skip dead-code blocks
analyzer.setSkipDeadCodeBlocks(true / false);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.coley</groupId>
<artifactId>analysis</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>
<name>Sim Analyzer</name>
<description>An ASM analyzer that performs minimal simulations</description>
<!--
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/me/coley/analysis/SimInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,15 @@ public AbstractValue copyOperation(AbstractInsnNode insn, AbstractValue value) t
// DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP
break;
}
// Very simple type verification, don't try to mix primitives and non-primitives
// Very simple type verification
Type argType = value.getType();
if(insnType != null && argType != null) {
// Check if we are trying to store a wider value into a narrower type
if (!load && insnType.getSort() < argType.getSort()) {
throw new AnalyzerException(insn, "Cannot store wider type (" + argType.getDescriptor() +
") into narrower type: " + insnType.getDescriptor());
}
// Don't try to mix primitives and non-primitives
if(insnType.getSort() == Type.OBJECT && isPrimitive(argType))
throw new AnalyzerException(insn, "Cannot mix primitive value with type-variable instruction");
else if(argType.getSort() == Type.OBJECT && isPrimitive(insnType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class TestCustomIllegalClasses extends TestUtils {
@ParameterizedTest
@ValueSource(strings = {
"bin/custom/illegal/vars/DoubleStoreAsInt.class",
"bin/custom/illegal/vars/IntToObject.class",
"bin/custom/illegal/vars/LongToInt.class",
"bin/custom/illegal/vars/StringToInt.class"
Expand Down
Binary file not shown.

0 comments on commit 4fa201e

Please sign in to comment.