Skip to content

Commit

Permalink
Merge pull request #690 from oxeye-gal/invokedynamic-workaround
Browse files Browse the repository at this point in the history
Adding workaround for JDK > 8 invokedynamic tainting
  • Loading branch information
h3xstream committed Jul 26, 2023
2 parents b4726c1 + 931f570 commit 68628d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class FindSecBugsGlobalConfig {
private boolean debugPrintInstructionVisited = false;
private boolean debugPrintInvocationVisited = false;
private boolean debugTaintState = false;
private boolean workaroundVisitInvokeDynamic = false;
private boolean verboseLocationReport = false;

// set through SystemProperties
Expand All @@ -48,6 +49,7 @@ protected FindSecBugsGlobalConfig() {
taintedMainArgument = Boolean.parseBoolean(loadFromSystem("findsecbugs.taint.taintedmainargument", Boolean.TRUE.toString()));
reportPotentialXssWrongContext = Boolean.parseBoolean(loadFromSystem("findsecbugs.taint.reportpotentialxsswrongcontext", Boolean.FALSE.toString()));
debugTaintState = Boolean.parseBoolean(loadFromSystem("findsecbugs.taint.debugtaintstate", Boolean.FALSE.toString()));
workaroundVisitInvokeDynamic = Boolean.parseBoolean(loadFromSystem("findsecbugs.taint.workaroundvisitinvokedynamic", Boolean.FALSE.toString()));
verboseLocationReport = Boolean.parseBoolean(loadFromSystem("findsecbugs.taint.verboselocationreport", Boolean.FALSE.toString()));
}

Expand Down Expand Up @@ -96,6 +98,11 @@ public boolean isDebugOutputTaintConfigs() {
return debugOutputTaintConfigs;
}


public boolean isWorkaroundVisitInvokeDynamic() {
return workaroundVisitInvokeDynamic;
}

public boolean isVerboseLocationReport() {
return verboseLocationReport;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ private boolean isFieldType(String typeSignature) {
return typeSignature != null && typeSignature.length() > 2 && typeSignature.charAt(0) != 'L';
}

public int getMethodIdParamCount(String methodId) {
String signature = methodId.substring(methodId.indexOf("("), methodId.length());
SignatureParser p = new SignatureParser(signature);
return p.getNumParameters();
}

public TaintMethodConfig getMethodConfig(TaintFrame frame, MethodDescriptor methodDescriptor, String className, String methodId) {
TaintMethodConfig taintMethodConfig = getTaintMethodConfigWithArgumentsAndLocation(frame, methodDescriptor, className, methodId);

Expand All @@ -227,6 +233,17 @@ public TaintMethodConfig getMethodConfig(TaintFrame frame, MethodDescriptor meth
taintMethodConfig = getSuperMethodConfig(className, methodId);
}

if (taintMethodConfig == null && methodId.indexOf("makeConcatWithConstants") > 0) {
taintMethodConfig = new TaintMethodConfig(true);
Taint t = new Taint(Taint.State.UNKNOWN);
int paramCount = getMethodIdParamCount(methodId);
for(int i=0; i < paramCount; i++) {
t.addParameter(i);
}
taintMethodConfig.setOuputTaint(t);
taintMethodConfig.addMutableStackIndex(1);
}

return taintMethodConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ public void visitINVOKEVIRTUAL(INVOKEVIRTUAL obj) {
visitInvoke(obj);
}

@Override
public void visitINVOKEDYNAMIC(INVOKEDYNAMIC obj) {
if(FindSecBugsGlobalConfig.getInstance().isWorkaroundVisitInvokeDynamic()) {
visitInvoke(obj);
} else {
handleNormalInstruction(obj);
}
}
@Override
public void visitANEWARRAY(ANEWARRAY obj) {
try {
Expand Down

0 comments on commit 68628d3

Please sign in to comment.