Skip to content

Commit 78d4745

Browse files
authored
Merge pull request #16578 from michaelnebel/java/dontliftneutral
Java: Do not lift neutrals in Model generation.
2 parents f5c654b + 9cf0995 commit 78d4745

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ predicate isUninterestingForDataFlowModels(Callable api) {
8080
predicate isUninterestingForTypeBasedFlowModels(Callable api) { none() }
8181

8282
/**
83-
* A class of Callables that are relevant for generating summary, source and sinks models for.
83+
* A class of callables that are potentially relevant for generating summary, source, sink
84+
* and neutral models.
8485
*
85-
* In the Standard library and 3rd party libraries it the Callables that can be called
86-
* from outside the library itself.
86+
* In the Standard library and 3rd party libraries it is the callables (or callables that have a
87+
* super implementation) that can be called from outside the library itself.
8788
*/
8889
class TargetApiSpecific extends Callable {
8990
private Callable lift;
@@ -97,6 +98,11 @@ class TargetApiSpecific extends Callable {
9798
* Gets the callable that a model will be lifted to.
9899
*/
99100
Callable lift() { result = lift }
101+
102+
/**
103+
* Holds if this callable is relevant in terms of generating models.
104+
*/
105+
predicate isRelevant() { relevant(this) }
100106
}
101107

102108
private string isExtensible(Callable c) {
@@ -114,23 +120,21 @@ private string typeAsModel(Callable c) {
114120
)
115121
}
116122

117-
private predicate partialLiftedModel(
118-
TargetApiSpecific api, string type, string extensible, string name, string parameters
123+
private predicate partialModel(
124+
Callable api, string type, string extensible, string name, string parameters
119125
) {
120-
exists(Callable c | c = api.lift() |
121-
type = typeAsModel(c) and
122-
extensible = isExtensible(c) and
123-
name = c.getName() and
124-
parameters = ExternalFlow::paramsString(c)
125-
)
126+
type = typeAsModel(api) and
127+
extensible = isExtensible(api) and
128+
name = api.getName() and
129+
parameters = ExternalFlow::paramsString(api)
126130
}
127131

128132
/**
129133
* Computes the first 6 columns for MaD rows.
130134
*/
131135
string asPartialModel(TargetApiSpecific api) {
132136
exists(string type, string extensible, string name, string parameters |
133-
partialLiftedModel(api, type, extensible, name, parameters) and
137+
partialModel(api.lift(), type, extensible, name, parameters) and
134138
result =
135139
type + ";" //
136140
+ extensible + ";" //
@@ -145,7 +149,7 @@ string asPartialModel(TargetApiSpecific api) {
145149
*/
146150
string asPartialNeutralModel(TargetApiSpecific api) {
147151
exists(string type, string name, string parameters |
148-
partialLiftedModel(api, type, _, name, parameters) and
152+
partialModel(api, type, _, name, parameters) and
149153
result =
150154
type + ";" //
151155
+ name + ";" //

java/ql/src/utils/modelgenerator/internal/CaptureSummaryFlowQuery.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ string captureFlow(DataFlowTargetApi api) {
7979
*/
8080
string captureNoFlow(DataFlowTargetApi api) {
8181
not exists(DataFlowTargetApi api0 | exists(captureFlow(api0)) and api0.lift() = api.lift()) and
82+
api.isRelevant() and
8283
result = ModelPrinting::asNeutralSummaryModel(api)
8384
}

java/ql/test/utils/modelgenerator/dataflow/p/ImplOfExternalSPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class ImplOfExternalSPI extends AbstractImplOfExternalSPI {
88

99
// sink=p;AbstractImplOfExternalSPI;true;accept;(File);;Argument[0];path-injection;df-generated
10-
// neutral=p;AbstractImplOfExternalSPI;accept;(File);summary;df-generated
10+
// neutral=p;ImplOfExternalSPI;accept;(File);summary;df-generated
1111
@Override
1212
public boolean accept(File pathname) {
1313
try {

java/ql/test/utils/modelgenerator/dataflow/p/Inheritance.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,28 @@ public String id(String s) {
8888
return s;
8989
}
9090
}
91+
92+
public interface INeutral {
93+
String id(String s);
94+
}
95+
96+
public class F implements INeutral {
97+
// neutral=p;Inheritance$F;id;(String);summary;df-generated
98+
public String id(String s) {
99+
return "";
100+
}
101+
}
102+
103+
public class G implements INeutral {
104+
// neutral=p;Inheritance$G;id;(String);summary;df-generated
105+
public String id(String s) {
106+
return "";
107+
}
108+
}
109+
110+
private class H implements INeutral {
111+
public String id(String s) {
112+
return "";
113+
}
114+
}
91115
}

java/ql/test/utils/modelgenerator/dataflow/p/PrivateFlowViaPublicInterface.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public OutputStream openStream() throws IOException {
4545
return null;
4646
}
4747

48-
// neutral=p;PrivateFlowViaPublicInterface$SPI;openStreamNone;();summary;df-generated
4948
@Override
5049
public OutputStream openStreamNone() throws IOException {
5150
return new FileOutputStream(new RandomPojo().someFile);

0 commit comments

Comments
 (0)