mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Java: Allow null literals as sources in data flow.
This commit is contained in:
@@ -235,6 +235,8 @@ DataFlowType getErasedRepr(Type t) {
|
||||
then result.(BoxedType).getPrimitiveType().getName() = "boolean"
|
||||
else result = e
|
||||
)
|
||||
or
|
||||
t instanceof NullType and result instanceof TypeObject
|
||||
}
|
||||
|
||||
/** Gets a string representation of a type returned by `getErasedRepr`. */
|
||||
|
||||
9
java/ql/test/library-tests/dataflow/null/A.java
Normal file
9
java/ql/test/library-tests/dataflow/null/A.java
Normal file
@@ -0,0 +1,9 @@
|
||||
public class A {
|
||||
void sink(Object o) { }
|
||||
|
||||
void foo() {
|
||||
Object src = null;
|
||||
Object x = src;
|
||||
sink(x);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
| A.java:5:18:5:21 | null | A.java:2:13:2:20 | o |
|
||||
| A.java:5:18:5:21 | null | A.java:5:18:5:21 | null |
|
||||
| A.java:5:18:5:21 | null | A.java:6:16:6:18 | src |
|
||||
| A.java:5:18:5:21 | null | A.java:7:10:7:10 | x |
|
||||
14
java/ql/test/library-tests/dataflow/null/testnullflow.ql
Normal file
14
java/ql/test/library-tests/dataflow/null/testnullflow.ql
Normal file
@@ -0,0 +1,14 @@
|
||||
import java
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
|
||||
class Conf extends DataFlow::Configuration {
|
||||
Conf() { this = "qqconf" }
|
||||
|
||||
override predicate isSource(DataFlow::Node n) { n.asExpr() instanceof NullLiteral }
|
||||
|
||||
override predicate isSink(DataFlow::Node n) { any() }
|
||||
}
|
||||
|
||||
from Conf conf, DataFlow::Node src, DataFlow::Node sink
|
||||
where conf.hasFlow(src, sink)
|
||||
select src, sink
|
||||
Reference in New Issue
Block a user