Skip to content

Commit dd517a4

Browse files
authored
Merge pull request #2671 from aschackmull/java/null-flow
Java: Allow null literals as sources in data flow.
2 parents b892734 + b92203a commit dd517a4

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

java/ql/src/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ DataFlowType getErasedRepr(Type t) {
235235
then result.(BoxedType).getPrimitiveType().getName() = "boolean"
236236
else result = e
237237
)
238+
or
239+
t instanceof NullType and result instanceof TypeObject
238240
}
239241

240242
/** Gets a string representation of a type returned by `getErasedRepr`. */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class A {
2+
void sink(Object o) { }
3+
4+
void foo() {
5+
Object src = null;
6+
Object x = src;
7+
sink(x);
8+
}
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| A.java:5:18:5:21 | null | A.java:2:13:2:20 | o |
2+
| A.java:5:18:5:21 | null | A.java:5:18:5:21 | null |
3+
| A.java:5:18:5:21 | null | A.java:6:16:6:18 | src |
4+
| A.java:5:18:5:21 | null | A.java:7:10:7:10 | x |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java
2+
import semmle.code.java.dataflow.DataFlow
3+
4+
class Conf extends DataFlow::Configuration {
5+
Conf() { this = "qqconf" }
6+
7+
override predicate isSource(DataFlow::Node n) { n.asExpr() instanceof NullLiteral }
8+
9+
override predicate isSink(DataFlow::Node n) { any() }
10+
}
11+
12+
from Conf conf, DataFlow::Node src, DataFlow::Node sink
13+
where conf.hasFlow(src, sink)
14+
select src, sink

0 commit comments

Comments
 (0)