Skip to content

Automodel: Apply negative characteristics only to endpoints of the right kind. #15326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ abstract private class ApplicationModeEndpoint extends TApplicationModeEndpoint
else none() // if both exist, it would be a summaryModel (not yet supported)
}

/**
* Gets a potential type of this endpoint to make sure that sources are
* associated with source types and sinks with sink types.
*/
AutomodelEndpointTypes::EndpointType getAPotentialType() {
this.getExtensibleType() = "sourceModel" and
result instanceof AutomodelEndpointTypes::SourceType
or
this.getExtensibleType() = "sinkModel" and
result instanceof AutomodelEndpointTypes::SinkType
}

abstract string toString();
}

Expand Down
12 changes: 12 additions & 0 deletions java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ abstract class FrameworkModeEndpoint extends TFrameworkModeEndpoint {

abstract string getExtensibleType();

/**
* Gets a potential type of this endpoint to make sure that sources are
* associated with source types and sinks with sink types.
*/
AutomodelEndpointTypes::EndpointType getAPotentialType() {
this.getExtensibleType() = "sourceModel" and
result instanceof AutomodelEndpointTypes::SourceType
or
this.getExtensibleType() = "sinkModel" and
result instanceof AutomodelEndpointTypes::SinkType
}

string toString() { result = this.asTop().toString() }

Location getLocation() { result = this.asTop().getLocation() }
Expand Down
11 changes: 7 additions & 4 deletions java/ql/automodel/src/AutomodelSharedCharacteristics.qll
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ signature module CandidateSig {
* An endpoint is a potential candidate for modeling. This will typically be bound to the language's
* DataFlow node class, or a subtype thereof.
*/
class Endpoint;
class Endpoint {
EndpointType getAPotentialType();
}

/**
* A related location for an endpoint. This will typically be bound to the supertype of all AST nodes (eg., `Top`).
Expand Down Expand Up @@ -122,9 +124,10 @@ module SharedCharacteristics<CandidateSig Candidate> {
*
* A candidate is an endpoint that cannot be excluded from `endpointType` based on its characteristics.
*/
predicate isCandidate(Candidate::Endpoint candidateSink, Candidate::EndpointType sinkType) {
not sinkType instanceof Candidate::NegativeEndpointType and
not exists(getAnExcludingCharacteristic(candidateSink, sinkType))
predicate isCandidate(Candidate::Endpoint endpoint, Candidate::EndpointType endpointType) {
not endpointType instanceof Candidate::NegativeEndpointType and
endpointType = endpoint.getAPotentialType() and
not exists(getAnExcludingCharacteristic(endpoint, endpointType))
}

/**
Expand Down