use getCallable predicate

This commit is contained in:
Stephan Brandauer
2023-05-03 11:27:14 +02:00
parent 09f3296134
commit 05bf13b020
3 changed files with 18 additions and 23 deletions

View File

@@ -78,11 +78,11 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
string ext, string input
) {
package = e.getEnclosingCallable().getDeclaringType().getPackage().toString() and
type = e.getEnclosingCallable().getDeclaringType().getName() and
package = getCallable(e).getDeclaringType().getPackage().toString() and
type = getCallable(e).getDeclaringType().getName() and
subtypes = false and
name = e.getEnclosingCallable().getName() and
signature = ExternalFlow::paramsString(e.getEnclosingCallable()) and
name = getCallable(e).getName() and
signature = ExternalFlow::paramsString(getCallable(e)) and
ext = "" and
exists(int paramIdx | e.isParameterOf(_, paramIdx) | input = "Argument[" + paramIdx + "]")
}
@@ -116,13 +116,15 @@ module CandidatesImpl implements SharedCharacteristics::CandidateSig {
RelatedLocation getRelatedLocation(Endpoint e, string name) {
name = "Callable-JavaDoc" and
result = e.getEnclosingCallable().(Documentable).getJavadoc()
result = getCallable(e).(Documentable).getJavadoc()
or
name = "Class-JavaDoc" and
result = e.getEnclosingCallable().getDeclaringType().(Documentable).getJavadoc()
result = getCallable(e).getDeclaringType().(Documentable).getJavadoc()
}
}
Callable getCallable(Endpoint e) { result = e.getEnclosingCallable() }
module CharacteristicsImpl = SharedCharacteristics::SharedCharacteristics<CandidatesImpl>;
class EndpointCharacteristic = CharacteristicsImpl::EndpointCharacteristic;
@@ -180,8 +182,8 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
override predicate appliesToEndpoint(Endpoint e) {
not CandidatesImpl::isSink(e, _) and
e.getEnclosingCallable().getName().matches("is%") and
e.getEnclosingCallable().getReturnType() instanceof BooleanType
getCallable(e).getName().matches("is%") and
getCallable(e).getReturnType() instanceof BooleanType
}
}
@@ -199,7 +201,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
override predicate appliesToEndpoint(Endpoint e) {
not CandidatesImpl::isSink(e, _) and
exists(Callable callable |
callable = e.getEnclosingCallable() and
callable = getCallable(e) and
(
callable.getName().toLowerCase() = "exists" or
callable.getName().toLowerCase() = "notexists"
@@ -216,7 +218,7 @@ private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkChara
ExceptionCharacteristic() { this = "exception" }
override predicate appliesToEndpoint(Endpoint e) {
e.getEnclosingCallable().getDeclaringType().getASupertype*() instanceof TypeThrowable
getCallable(e).getDeclaringType().getASupertype*() instanceof TypeThrowable
}
}
@@ -257,7 +259,7 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
{
NonPublicMethodCharacteristic() { this = "non-public method" }
override predicate appliesToEndpoint(Endpoint e) { not e.getEnclosingCallable().isPublic() }
override predicate appliesToEndpoint(Endpoint e) { not getCallable(e).isPublic() }
}
/**

View File

@@ -21,17 +21,10 @@ where
// Extract positive examples of sinks belonging to the existing ATM query configurations.
(
CharacteristicsImpl::isKnownSink(sink, sinkType) and
// If there are _any_ erroneous endpoints, return an error message for all rows. This will prevent us from
// accidentally running this query when there's a codex-generated data extension file in `java/ql/lib/ext`.
if not erroneousEndpoints(_, _, _, _, _, true)
then
message =
sinkType + "\n" +
// Extract the needed metadata for this endpoint.
any(string metadata | CharacteristicsImpl::hasMetadata(sink, metadata))
else
message =
"Error: There are erroneous endpoints! Please check whether there's a codex-generated data extension file in `java/ql/lib/ext`."
message =
sinkType + "\n" +
// Extract the needed metadata for this endpoint.
any(string metadata | CharacteristicsImpl::hasMetadata(sink, metadata))
)
select sink, message + "\nrelated locations: $@, $@",
CharacteristicsImpl::getRelatedLocationOrCandidate(sink, "Callable-JavaDoc"),

View File

@@ -19,7 +19,7 @@ signature module CandidateSig {
class Endpoint;
/**
* A related location for an endpoint. This will typically be bound to the supertype of all AST nodes.
* A related location for an endpoint. This will typically be bound to the supertype of all AST nodes (eg., `Top`).
*/
class RelatedLocation;