Skip to content

Commit d1d213d

Browse files
authored
Merge pull request github#15632 from aschackmull/dataflow/flowfeature-bugfix
Dataflow: Fix flow-feature bug for parameterless static functions
2 parents b927968 + 03f7968 commit d1d213d

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
public class A {
2+
static Object source(String s) { return null; }
3+
static void sink(Object o) { }
4+
5+
static Object id(Object x) { return x; }
6+
7+
static void test1(int dummy) {
8+
Object src = source("1");
9+
Object a = src;
10+
sink(a); // $ EqCc="1" SrcCc="1" SinkCc="1"
11+
}
12+
13+
static void test2() {
14+
Object src = source("2");
15+
Object a = src;
16+
sink(a); // $ EqCc="2" SrcCc="2" SinkCc="2"
17+
}
18+
19+
void test3() {
20+
Object src = source("3");
21+
Object a = id(src);
22+
sink(a); // $ EqCc="3" SrcCc="3" SinkCc="3"
23+
}
24+
25+
static void test4() {
26+
Object src = source("4");
27+
Object a = id(src);
28+
sink(a); // $ EqCc="4" SrcCc="4" SinkCc="4"
29+
}
30+
31+
static Object test5src() {
32+
return source("5");
33+
}
34+
35+
static void test5() {
36+
Object x = test5src();
37+
Object y = id(x);
38+
sink(y); // $ SinkCc="5"
39+
}
40+
41+
static void test6sink(Object x) {
42+
sink(x); // $ SrcCc="6"
43+
}
44+
45+
static void test6() {
46+
Object x = source("6");
47+
test6sink(x);
48+
}
49+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import java
2+
import semmle.code.java.dataflow.DataFlow
3+
import TestUtilities.InlineExpectationsTest
4+
5+
module Base {
6+
predicate isSource(DataFlow::Node n) { n.asExpr().(MethodCall).getMethod().hasName("source") }
7+
8+
predicate isSink(DataFlow::Node n) {
9+
exists(MethodCall ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
10+
}
11+
}
12+
13+
module ConfigSourceCc implements DataFlow::ConfigSig {
14+
import Base
15+
16+
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSourceCallContext }
17+
}
18+
19+
module ConfigSinkCc implements DataFlow::ConfigSig {
20+
import Base
21+
22+
DataFlow::FlowFeature getAFeature() { result instanceof DataFlow::FeatureHasSinkCallContext }
23+
}
24+
25+
module ConfigEqualCc implements DataFlow::ConfigSig {
26+
import Base
27+
28+
DataFlow::FlowFeature getAFeature() {
29+
result instanceof DataFlow::FeatureEqualSourceSinkCallContext
30+
}
31+
}
32+
33+
module FlowSourceCc = DataFlow::Global<ConfigSourceCc>;
34+
35+
module FlowSinkCc = DataFlow::Global<ConfigSinkCc>;
36+
37+
module FlowEqualCc = DataFlow::Global<ConfigEqualCc>;
38+
39+
module HasFlowTest implements TestSig {
40+
string getARelevantTag() { result = ["SrcCc", "SinkCc", "EqCc"] }
41+
42+
predicate hasActualResult(Location location, string element, string tag, string value) {
43+
exists(DataFlow::Node src, DataFlow::Node sink |
44+
tag = "SrcCc" and
45+
FlowSourceCc::flow(src, sink)
46+
or
47+
tag = "SinkCc" and
48+
FlowSinkCc::flow(src, sink)
49+
or
50+
tag = "EqCc" and
51+
FlowEqualCc::flow(src, sink)
52+
|
53+
sink.getLocation() = location and
54+
element = sink.toString() and
55+
value = src.asExpr().(MethodCall).getAnArgument().toString()
56+
)
57+
}
58+
}
59+
60+
import MakeTest<HasFlowTest>

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,9 +1551,7 @@ module MakeImplCommon<InputSig Lang> {
15511551
class CallContextSomeCall extends CallContextCall, TSomeCall {
15521552
override string toString() { result = "CcSomeCall" }
15531553

1554-
override predicate relevantFor(DataFlowCallable callable) {
1555-
exists(ParamNode p | getNodeEnclosingCallable(p) = callable)
1556-
}
1554+
override predicate relevantFor(DataFlowCallable callable) { any() }
15571555

15581556
override predicate matchesCall(DataFlowCall call) { any() }
15591557
}

0 commit comments

Comments
 (0)