Skip to content

Commit f87cb4d

Browse files
committed
Java/C++/C#: Address review comments and fix test.
1 parent f979582 commit f87cb4d

File tree

10 files changed

+132
-3
lines changed

10 files changed

+132
-3
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ private module ImplCommon {
3434
)
3535
}
3636

37+
/*
38+
* The `FlowThrough_*` modules take a `step` relation as input and provide
39+
* an `argumentValueFlowsThrough` relation as output.
40+
*
41+
* `FlowThrough_v1` includes just `simpleLocalFlowStep`, which is then used
42+
* to detect getters and setters.
43+
* `FlowThrough_v2` then includes a little bit of local field flow on top
44+
* of `simpleLocalFlowStep`.
45+
*/
46+
3747
private module FlowThrough_v1 {
3848
private predicate step = simpleLocalFlowStep/2;
3949

@@ -233,6 +243,11 @@ private module ImplCommon {
233243
FlowThrough_v1::argumentValueFlowsThrough(node1, node2, _)
234244
}
235245

246+
/**
247+
* Holds if `p` can flow to `node` in the same callable allowing local flow
248+
* steps and value flow through methods. Call contexts are only accounted
249+
* for in the nested calls.
250+
*/
236251
private predicate parameterValueFlowNoCtx(ParameterNode p, Node node) {
237252
p = node
238253
or

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ private module ImplCommon {
3434
)
3535
}
3636

37+
/*
38+
* The `FlowThrough_*` modules take a `step` relation as input and provide
39+
* an `argumentValueFlowsThrough` relation as output.
40+
*
41+
* `FlowThrough_v1` includes just `simpleLocalFlowStep`, which is then used
42+
* to detect getters and setters.
43+
* `FlowThrough_v2` then includes a little bit of local field flow on top
44+
* of `simpleLocalFlowStep`.
45+
*/
46+
3747
private module FlowThrough_v1 {
3848
private predicate step = simpleLocalFlowStep/2;
3949

@@ -233,6 +243,11 @@ private module ImplCommon {
233243
FlowThrough_v1::argumentValueFlowsThrough(node1, node2, _)
234244
}
235245

246+
/**
247+
* Holds if `p` can flow to `node` in the same callable allowing local flow
248+
* steps and value flow through methods. Call contexts are only accounted
249+
* for in the nested calls.
250+
*/
236251
private predicate parameterValueFlowNoCtx(ParameterNode p, Node node) {
237252
p = node
238253
or

csharp/ql/src/semmle/code/csharp/Caching.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module Stages {
5050
cached
5151
module DataFlowStage {
5252
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
53-
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon
53+
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon::Public
5454
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
5555

5656
cached

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ private module ImplCommon {
3434
)
3535
}
3636

37+
/*
38+
* The `FlowThrough_*` modules take a `step` relation as input and provide
39+
* an `argumentValueFlowsThrough` relation as output.
40+
*
41+
* `FlowThrough_v1` includes just `simpleLocalFlowStep`, which is then used
42+
* to detect getters and setters.
43+
* `FlowThrough_v2` then includes a little bit of local field flow on top
44+
* of `simpleLocalFlowStep`.
45+
*/
46+
3747
private module FlowThrough_v1 {
3848
private predicate step = simpleLocalFlowStep/2;
3949

@@ -233,6 +243,11 @@ private module ImplCommon {
233243
FlowThrough_v1::argumentValueFlowsThrough(node1, node2, _)
234244
}
235245

246+
/**
247+
* Holds if `p` can flow to `node` in the same callable allowing local flow
248+
* steps and value flow through methods. Call contexts are only accounted
249+
* for in the nested calls.
250+
*/
236251
private predicate parameterValueFlowNoCtx(ParameterNode p, Node node) {
237252
p = node
238253
or

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ private import cil
33
private import dotnet
44
private import DataFlowPublic
55
private import DataFlowDispatch
6-
private import DataFlowImplCommon
76
private import ControlFlowReachability
87
private import DelegateDataFlow
98
private import semmle.code.csharp.Caching

csharp/ql/src/semmle/code/csharp/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
private import csharp
22
private import TaintTrackingPublic
3-
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon
43
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
54
private import semmle.code.csharp.dataflow.internal.ControlFlowReachability
65
private import semmle.code.csharp.dataflow.LibraryTypeDataFlow

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ private module ImplCommon {
3434
)
3535
}
3636

37+
/*
38+
* The `FlowThrough_*` modules take a `step` relation as input and provide
39+
* an `argumentValueFlowsThrough` relation as output.
40+
*
41+
* `FlowThrough_v1` includes just `simpleLocalFlowStep`, which is then used
42+
* to detect getters and setters.
43+
* `FlowThrough_v2` then includes a little bit of local field flow on top
44+
* of `simpleLocalFlowStep`.
45+
*/
46+
3747
private module FlowThrough_v1 {
3848
private predicate step = simpleLocalFlowStep/2;
3949

@@ -233,6 +243,11 @@ private module ImplCommon {
233243
FlowThrough_v1::argumentValueFlowsThrough(node1, node2, _)
234244
}
235245

246+
/**
247+
* Holds if `p` can flow to `node` in the same callable allowing local flow
248+
* steps and value flow through methods. Call contexts are only accounted
249+
* for in the nested calls.
250+
*/
236251
private predicate parameterValueFlowNoCtx(ParameterNode p, Node node) {
237252
p = node
238253
or
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
public class A {
2+
int foo;
3+
4+
int getFoo() {
5+
return this.foo;
6+
}
7+
8+
void setFoo(int x) {
9+
this.foo = x;
10+
}
11+
12+
static A withFoo(int x) {
13+
A a = new A();
14+
a.foo = x;
15+
return a;
16+
}
17+
18+
static void run() {
19+
A a = new A();
20+
a.setFoo(1);
21+
int x = a.getFoo();
22+
A a2 = withFoo(2);
23+
x = a.aGetter();
24+
x = a2.notAGetter();
25+
}
26+
27+
static class C1 {
28+
A maybeId(A a) {
29+
return a;
30+
}
31+
}
32+
33+
static class C2 extends C1 {
34+
@Override
35+
A maybeId(A a) {
36+
return new A();
37+
}
38+
}
39+
40+
static A maybeIdWrap(A a, C1 c) {
41+
return c.maybeId(a);
42+
}
43+
44+
int aGetter() {
45+
return maybeIdWrap(this, new C1()).foo;
46+
}
47+
48+
int notAGetter() {
49+
return maybeIdWrap(this, new C2()).foo;
50+
}
51+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| Read | A.java:5:12:5:15 | this | A.java:5:12:5:19 | this.foo | A.java:2:7:2:9 | foo |
2+
| Read | A.java:21:13:21:13 | a | A.java:21:13:21:22 | getFoo(...) | A.java:2:7:2:9 | foo |
3+
| Read | A.java:23:9:23:9 | a | A.java:23:9:23:19 | aGetter(...) | A.java:2:7:2:9 | foo |
4+
| Read | A.java:45:12:45:38 | maybeIdWrap(...) | A.java:45:12:45:42 | maybeIdWrap(...).foo | A.java:2:7:2:9 | foo |
5+
| Read | A.java:49:12:49:38 | maybeIdWrap(...) | A.java:49:12:49:42 | maybeIdWrap(...).foo | A.java:2:7:2:9 | foo |
6+
| Store | A.java:9:16:9:16 | x | A.java:9:5:9:8 | this [post update] | A.java:2:7:2:9 | foo |
7+
| Store | A.java:14:13:14:13 | x | A.java:14:5:14:5 | a [post update] | A.java:2:7:2:9 | foo |
8+
| Store | A.java:20:14:20:14 | 1 | A.java:20:5:20:5 | a [post update] | A.java:2:7:2:9 | foo |
9+
| Store | A.java:22:20:22:20 | 2 | A.java:22:12:22:21 | withFoo(...) | A.java:2:7:2:9 | foo |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
import semmle.code.java.dataflow.internal.DataFlowImplCommon::Public
3+
import semmle.code.java.dataflow.internal.DataFlowImplSpecific::Public
4+
import semmle.code.java.dataflow.internal.DataFlowImplSpecific::Private
5+
6+
from Node n1, Content f, Node n2, string k
7+
where
8+
read(n1, f, n2) and k = "Read"
9+
or
10+
store(n1, f, n2) and k = "Store"
11+
select k, n1, n2, f

0 commit comments

Comments
 (0)