Skip to content

Commit 05bf13b

Browse files
author
Stephan Brandauer
committed
use getCallable predicate
1 parent 09f3296 commit 05bf13b

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

java/ql/src/Telemetry/AutomodelEndpointCharacteristics.qll

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
7878
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
7979
string ext, string input
8080
) {
81-
package = e.getEnclosingCallable().getDeclaringType().getPackage().toString() and
82-
type = e.getEnclosingCallable().getDeclaringType().getName() and
81+
package = getCallable(e).getDeclaringType().getPackage().toString() and
82+
type = getCallable(e).getDeclaringType().getName() and
8383
subtypes = false and
84-
name = e.getEnclosingCallable().getName() and
85-
signature = ExternalFlow::paramsString(e.getEnclosingCallable()) and
84+
name = getCallable(e).getName() and
85+
signature = ExternalFlow::paramsString(getCallable(e)) and
8686
ext = "" and
8787
exists(int paramIdx | e.isParameterOf(_, paramIdx) | input = "Argument[" + paramIdx + "]")
8888
}
@@ -116,13 +116,15 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
116116

117117
RelatedLocation getRelatedLocation(Endpoint e, string name) {
118118
name = "Callable-JavaDoc" and
119-
result = e.getEnclosingCallable().(Documentable).getJavadoc()
119+
result = getCallable(e).(Documentable).getJavadoc()
120120
or
121121
name = "Class-JavaDoc" and
122-
result = e.getEnclosingCallable().getDeclaringType().(Documentable).getJavadoc()
122+
result = getCallable(e).getDeclaringType().(Documentable).getJavadoc()
123123
}
124124
}
125125

126+
Callable getCallable(Endpoint e) { result = e.getEnclosingCallable() }
127+
126128
module CharacteristicsImpl = SharedCharacteristics::SharedCharacteristics<CandidatesImpl>;
127129

128130
class EndpointCharacteristic = CharacteristicsImpl::EndpointCharacteristic;
@@ -180,8 +182,8 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
180182

181183
override predicate appliesToEndpoint(Endpoint e) {
182184
not CandidatesImpl::isSink(e, _) and
183-
e.getEnclosingCallable().getName().matches("is%") and
184-
e.getEnclosingCallable().getReturnType() instanceof BooleanType
185+
getCallable(e).getName().matches("is%") and
186+
getCallable(e).getReturnType() instanceof BooleanType
185187
}
186188
}
187189

@@ -199,7 +201,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
199201
override predicate appliesToEndpoint(Endpoint e) {
200202
not CandidatesImpl::isSink(e, _) and
201203
exists(Callable callable |
202-
callable = e.getEnclosingCallable() and
204+
callable = getCallable(e) and
203205
(
204206
callable.getName().toLowerCase() = "exists" or
205207
callable.getName().toLowerCase() = "notexists"
@@ -216,7 +218,7 @@ private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkChara
216218
ExceptionCharacteristic() { this = "exception" }
217219

218220
override predicate appliesToEndpoint(Endpoint e) {
219-
e.getEnclosingCallable().getDeclaringType().getASupertype*() instanceof TypeThrowable
221+
getCallable(e).getDeclaringType().getASupertype*() instanceof TypeThrowable
220222
}
221223
}
222224

@@ -257,7 +259,7 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
257259
{
258260
NonPublicMethodCharacteristic() { this = "non-public method" }
259261

260-
override predicate appliesToEndpoint(Endpoint e) { not e.getEnclosingCallable().isPublic() }
262+
override predicate appliesToEndpoint(Endpoint e) { not getCallable(e).isPublic() }
261263
}
262264

263265
/**

java/ql/src/Telemetry/AutomodelExtractPositiveExamples.ql

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@ where
2121
// Extract positive examples of sinks belonging to the existing ATM query configurations.
2222
(
2323
CharacteristicsImpl::isKnownSink(sink, sinkType) and
24-
// If there are _any_ erroneous endpoints, return an error message for all rows. This will prevent us from
25-
// accidentally running this query when there's a codex-generated data extension file in `java/ql/lib/ext`.
26-
if not erroneousEndpoints(_, _, _, _, _, true)
27-
then
28-
message =
29-
sinkType + "\n" +
30-
// Extract the needed metadata for this endpoint.
31-
any(string metadata | CharacteristicsImpl::hasMetadata(sink, metadata))
32-
else
33-
message =
34-
"Error: There are erroneous endpoints! Please check whether there's a codex-generated data extension file in `java/ql/lib/ext`."
24+
message =
25+
sinkType + "\n" +
26+
// Extract the needed metadata for this endpoint.
27+
any(string metadata | CharacteristicsImpl::hasMetadata(sink, metadata))
3528
)
3629
select sink, message + "\nrelated locations: $@, $@",
3730
CharacteristicsImpl::getRelatedLocationOrCandidate(sink, "Callable-JavaDoc"),

java/ql/src/Telemetry/AutomodelSharedCharacteristics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ signature module CandidateSig {
1919
class Endpoint;
2020

2121
/**
22-
* A related location for an endpoint. This will typically be bound to the supertype of all AST nodes.
22+
* A related location for an endpoint. This will typically be bound to the supertype of all AST nodes (eg., `Top`).
2323
*/
2424
class RelatedLocation;
2525

0 commit comments

Comments
 (0)