Skip to content

Commit a3f27d4

Browse files
authored
Merge pull request #10131 from atorralba/atorralba/path-steps
Java: Add new java.nio.Path{,s} summary models
2 parents 5fb3119 + ee6ac74 commit a3f27d4

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added new flow steps for the classes `java.io.Path` and `java.nio.Paths`.

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ private predicate summaryModelCsv(string row) {
317317
"java.io;File;true;getAbsolutePath;;;Argument[-1];ReturnValue;taint;manual",
318318
"java.io;File;true;getCanonicalPath;;;Argument[-1];ReturnValue;taint;manual",
319319
"java.nio;ByteBuffer;false;array;();;Argument[-1];ReturnValue;taint;manual",
320+
"java.nio.file;Path;true;normalize;;;Argument[-1];ReturnValue;taint;manual",
321+
"java.nio.file;Path;true;resolve;;;Argument[-1..0];ReturnValue;taint;manual",
320322
"java.nio.file;Path;false;toFile;;;Argument[-1];ReturnValue;taint;manual",
323+
"java.nio.file;Path;true;toString;;;Argument[-1];ReturnValue;taint;manual",
324+
"java.nio.file;Path;true;toUri;;;Argument[-1];ReturnValue;taint;manual",
325+
"java.nio.file;Paths;true;get;;;Argument[0..1];ReturnValue;taint;manual",
321326
"java.io;BufferedReader;true;readLine;;;Argument[-1];ReturnValue;taint;manual",
322327
"java.io;Reader;true;read;();;Argument[-1];ReturnValue;taint;manual",
323328
// arg to return
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package generatedtest;
2+
3+
import java.io.File;
4+
import java.net.URI;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
8+
// Test case generated by GenerateFlowTestCase.ql
9+
public class Test {
10+
11+
Object source() { return null; }
12+
void sink(Object o) { }
13+
14+
public void test() throws Exception {
15+
16+
{
17+
// "java.nio.file;Path;true;normalize;;;Argument[-1];ReturnValue;taint;manual"
18+
Path out = null;
19+
Path in = (Path)source();
20+
out = in.normalize();
21+
sink(out); // $ hasTaintFlow
22+
}
23+
{
24+
// "java.nio.file;Path;true;resolve;;;Argument[-1..0];ReturnValue;taint;manual"
25+
Path out = null;
26+
Path in = (Path)source();
27+
Path instance = null;
28+
out = instance.resolve(in);
29+
sink(out); // $ hasTaintFlow
30+
}
31+
{
32+
// "java.nio.file;Path;true;resolve;;;Argument[-1..0];ReturnValue;taint;manual"
33+
Path out = null;
34+
Path in = (Path)source();
35+
out = in.resolve((Path)null);
36+
sink(out); // $ hasTaintFlow
37+
}
38+
{
39+
// "java.nio.file;Path;true;resolve;;;Argument[-1..0];ReturnValue;taint;manual"
40+
Path out = null;
41+
Path in = (Path)source();
42+
out = in.resolve((String)null);
43+
sink(out); // $ hasTaintFlow
44+
}
45+
{
46+
// "java.nio.file;Path;true;resolve;;;Argument[-1..0];ReturnValue;taint;manual"
47+
Path out = null;
48+
String in = (String)source();
49+
Path instance = null;
50+
out = instance.resolve(in);
51+
sink(out); // $ hasTaintFlow
52+
}
53+
{
54+
// "java.nio.file;Path;true;toFile;;;Argument[-1];ReturnValue;taint;manual"
55+
File out = null;
56+
Path in = (Path)source();
57+
out = in.toFile();
58+
sink(out); // $ hasTaintFlow
59+
}
60+
{
61+
// "java.nio.file;Path;true;toString;;;Argument[-1];ReturnValue;taint;manual"
62+
String out = null;
63+
Path in = (Path)source();
64+
out = in.toString();
65+
sink(out); // $ hasTaintFlow
66+
}
67+
{
68+
// "java.nio.file;Path;true;toUri;;;Argument[-1];ReturnValue;taint;manual"
69+
URI out = null;
70+
Path in = (Path)source();
71+
out = in.toUri();
72+
sink(out); // $ hasTaintFlow
73+
}
74+
{
75+
// "java.nio.file;Paths;true;get;;;Argument[0..1];ReturnValue;taint;manual"
76+
Path out = null;
77+
String in = (String)source();
78+
out = Paths.get(in, (String[])null);
79+
sink(out); // $ hasTaintFlow
80+
}
81+
{
82+
// "java.nio.file;Paths;true;get;;;Argument[0..1];ReturnValue;taint;manual"
83+
Path out = null;
84+
String[] in = (String[])source();
85+
out = Paths.get((String)null, in);
86+
sink(out); // $ hasTaintFlow
87+
}
88+
{
89+
// "java.nio.file;Paths;true;get;;;Argument[0..1];ReturnValue;taint;manual"
90+
Path out = null;
91+
URI in = (URI)source();
92+
out = Paths.get(in);
93+
sink(out); // $ hasTaintFlow
94+
}
95+
96+
}
97+
98+
}

java/ql/test/library-tests/paths/test.expected

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import java
2+
import TestUtilities.InlineFlowTest

0 commit comments

Comments
 (0)