Skip to content

Commit

Permalink
Merge pull request #330 from topolik/328
Browse files Browse the repository at this point in the history
Fix java/io/File#createTempFile #328
  • Loading branch information
h3xstream committed Aug 17, 2017
2 parents af59f67 + 5fd62d9 commit 2e669c6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void receiveTaintConfig(String typeSignature, String config) throws IOExc
throw new IllegalStateException("Config for " + typeSignature + " already loaded");
}
TaintMethodConfig taintMethodConfig = new TaintMethodConfig(true).load(config);
taintMethodConfig.setTypeSignature(typeSignature);
put(typeSignature, taintMethodConfig);
return;
}
Expand All @@ -104,6 +105,8 @@ public void receiveTaintConfig(String typeSignature, String config) throws IOExc
TaintMethodConfigWithArgumentsAndLocation methodConfig =
new TaintMethodConfigWithArgumentsAndLocation().load(config);

methodConfig.setTypeSignature(typeSignature);

String key = typeSignature + '@' + methodConfig.getLocation();
taintMethodConfigWithArgumentsAndLocationMap.put(key, methodConfig);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ private void transferTaintToMutables(TaintMethodConfig methodConfig, Taint taint
if (mutableStackIndex >= stackDepth) {
if (!Constants.CONSTRUCTOR_NAME.equals(methodDescriptor.getName())
&& !Constants.STATIC_INITIALIZER_NAME.equals(methodDescriptor.getName())) {
assert false : "Out of bounds mutables in " + methodDescriptor;
assert false : "Out of bounds mutables in " + methodDescriptor + " Method Config: " + methodConfig.toString();
}
continue; // ignore if assertions disabled or if in constructor
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class TaintMethodConfig implements TaintTypeConfig {
private Taint outputTaint = null;
private final Set<Integer> mutableStackIndices;
private final boolean isConfigured;
private String typeSignature;
public static final TaintMethodConfig SAFE_CONFIG;
protected static final Pattern fullMethodPattern;
protected static final Pattern configPattern;
Expand Down Expand Up @@ -215,9 +216,13 @@ public boolean isConfigured() {
@Override
public String toString() {
if (outputTaint == null) {
return "";
return typeSignature != null ? typeSignature : "";
}
StringBuilder sb = new StringBuilder();
if (typeSignature != null) {
sb.append(typeSignature);
sb.append(":");
}
if (outputTaint.isUnknown() && outputTaint.hasParameters()) {
appendJoined(sb, outputTaint.getParameters());
Taint.State nonParametricState = outputTaint.getNonParametricState();
Expand Down Expand Up @@ -448,4 +453,8 @@ private boolean isTaintStateValue(String value) {
}
return false;
}

public void setTypeSignature(String typeSignature) {
this.typeSignature = typeSignature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ java/io/FileReader.<init>(Ljava/lang/String;)V:0
java/io/FileInputStream.<init>(Ljava/lang/String;)V:0

java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;:0,1

java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;:0,1
java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;:0,1,2
4 changes: 2 additions & 2 deletions plugin/src/main/resources/taint-config/java-net.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ java/net/URL.toExternalForm()Ljava/lang/String;:0
java/net/URL.toString()Ljava/lang/String;:0
java/net/URL.toURI()Ljava/net/URI;:0

java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;:0,1#2,3
java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;:0,1,2#3,4
java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;:0,1
java/io/File.createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;:0,1,2
java/io/File.getCanonicalPath()Ljava/lang/String;:0
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void detectPathTraversal() throws Exception {
EasyBugReporter reporter = spy(new SecurityReporter());
analyze(files, reporter);

for (Integer line : Arrays.asList(17, 18, 19, 20, 22, 23)) {
for (Integer line : Arrays.asList(17, 18, 19, 20, 22, 23, 35, 36, 37)) {
verify(reporter).doReportBug(
bugDefinition()
.bugType("PATH_TRAVERSAL_IN")
Expand All @@ -61,7 +61,7 @@ public void detectPathTraversal() throws Exception {
);
}

verify(reporter, times(6)).doReportBug(bugDefinition().bugType("PATH_TRAVERSAL_IN").build());
verify(reporter, times(9)).doReportBug(bugDefinition().bugType("PATH_TRAVERSAL_IN").build());
verify(reporter, times(4)).doReportBug(bugDefinition().bugType("PATH_TRAVERSAL_OUT").build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ public static void main(String[] args) throws IOException, URISyntaxException {
new RandomAccessFile("safe", args[0]);
new FileWriter("safe".toUpperCase());
new File(new URI("safe"));

File.createTempFile(input, "safe");
File.createTempFile("safe", input);
File.createTempFile("safe", input, new File("safeDir"));
}
}

0 comments on commit 2e669c6

Please sign in to comment.