-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Re-use asPartialModel in utility and test code. #8449
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
Closed
michaelnebel
wants to merge
6
commits into
github:main
from
michaelnebel:csharp/share-aspartialmodel
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e41d609
C#: Add asPartialModel to DataFlowCallable.
michaelnebel 1275062
C#: Update existing test code to use asPartialModel as move the Relev…
michaelnebel c381157
C#: Collapse RelevantSummarizedCallable and IncludeSummarizedCallable.
michaelnebel d1179dd
C#: TargetApi on DataFlowCallable and re-use asPartialModel.
michaelnebel bb6a196
Java: Make asPartialModel a member predicate of TargetApi.
michaelnebel 95fe8aa
C#/Java: Use asPartialModel member predicate.
michaelnebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1022,46 +1022,6 @@ module Private { | |
} | ||
} | ||
|
||
/** Provides a query predicate for outputting a set of relevant flow summaries. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think it makes sense to have here, in case other languages want to use it later. |
||
module TestOutput { | ||
/** A flow summary to include in the `summary/3` query predicate. */ | ||
abstract class RelevantSummarizedCallable extends SummarizedCallable { | ||
/** Gets the string representation of this callable used by `summary/1`. */ | ||
abstract string getCallableCsv(); | ||
|
||
/** Holds if flow is propagated between `input` and `output`. */ | ||
predicate relevantSummary( | ||
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue | ||
) { | ||
this.propagatesFlow(input, output, preservesValue) | ||
} | ||
} | ||
|
||
/** Render the kind in the format used in flow summaries. */ | ||
private string renderKind(boolean preservesValue) { | ||
preservesValue = true and result = "value" | ||
or | ||
preservesValue = false and result = "taint" | ||
} | ||
|
||
/** | ||
* A query predicate for outputting flow summaries in semi-colon separated format in QL tests. | ||
* The syntax is: "namespace;type;overrides;name;signature;ext;inputspec;outputspec;kind", | ||
* ext is hardcoded to empty. | ||
*/ | ||
query predicate summary(string csv) { | ||
exists( | ||
RelevantSummarizedCallable c, SummaryComponentStack input, SummaryComponentStack output, | ||
boolean preservesValue | ||
| | ||
c.relevantSummary(input, output, preservesValue) and | ||
csv = | ||
c.getCallableCsv() + ";;" + getComponentStackCsv(input) + ";" + | ||
getComponentStackCsv(output) + ";" + renderKind(preservesValue) | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Provides query predicates for rendering the generated data flow graph for | ||
* a summarized callable. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import shared.FlowSummaries | ||
|
||
private class IncludeAllSummarizedCallable extends IncludeSummarizedCallable { | ||
private class IncludeAllSummarizedCallable extends RelevantSummarizedCallable { | ||
IncludeAllSummarizedCallable() { this instanceof SummarizedCallable } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
csharp/ql/test/library-tests/frameworks/EntityFramework/FlowSummaries.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import semmle.code.csharp.frameworks.EntityFramework::EntityFramework | ||
import shared.FlowSummaries | ||
|
||
private class IncludeEFSummarizedCallable extends IncludeSummarizedCallable { | ||
private class IncludeEFSummarizedCallable extends RelevantSummarizedCallable { | ||
IncludeEFSummarizedCallable() { this instanceof EFSummarizedCallable } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,40 @@ | ||
import semmle.code.csharp.dataflow.FlowSummary | ||
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl::Private::TestOutput | ||
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl | ||
|
||
abstract class IncludeSummarizedCallable extends RelevantSummarizedCallable { | ||
IncludeSummarizedCallable() { | ||
/** A flow summary to include in the `summary/3` query predicate. */ | ||
abstract class RelevantSummarizedCallable extends SummarizedCallable { | ||
RelevantSummarizedCallable() { | ||
[this.(Modifiable), this.(Accessor).getDeclaration()].isEffectivelyPublic() | ||
} | ||
|
||
/** Gets the qualified parameter types of this callable as a comma-separated string. */ | ||
private string parameterQualifiedTypeNamesToString() { | ||
result = | ||
concat(Parameter p, int i | | ||
p = this.getParameter(i) | ||
| | ||
p.getType().getQualifiedName(), "," order by i | ||
) | ||
} | ||
|
||
/** Holds if the summary should apply for all overrides of this. */ | ||
predicate isBaseCallableOrPrototype() { | ||
this.getDeclaringType() instanceof Interface | ||
or | ||
exists(Modifiable m | m = [this.(Modifiable), this.(Accessor).getDeclaration()] | | ||
m.isAbstract() | ||
or | ||
this.getDeclaringType().(Modifiable).isAbstract() and m.(Virtualizable).isVirtual() | ||
) | ||
/** Holds if flow is propagated between `input` and `output`. */ | ||
predicate relevantSummary( | ||
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue | ||
) { | ||
this.propagatesFlow(input, output, preservesValue) | ||
} | ||
} | ||
|
||
/** Gets a string representing whether the summary should apply for all overrides of this. */ | ||
private string getCallableOverride() { | ||
if this.isBaseCallableOrPrototype() then result = "true" else result = "false" | ||
} | ||
/** Render the kind in the format used in flow summaries. */ | ||
private string renderKind(boolean preservesValue) { | ||
preservesValue = true and result = "value" | ||
or | ||
preservesValue = false and result = "taint" | ||
} | ||
|
||
/** Gets a string representing the callable in semi-colon separated format for use in flow summaries. */ | ||
final override string getCallableCsv() { | ||
exists(string namespace, string type | | ||
this.getDeclaringType().hasQualifiedName(namespace, type) and | ||
result = | ||
namespace + ";" + type + ";" + this.getCallableOverride() + ";" + this.getName() + ";" + "(" | ||
+ this.parameterQualifiedTypeNamesToString() + ")" | ||
) | ||
} | ||
/** | ||
* A query predicate for outputting flow summaries in semi-colon separated format in QL tests. | ||
* The syntax is: "namespace;type;overrides;name;signature;ext;inputspec;outputspec;kind", | ||
* ext is hardcoded to empty. | ||
*/ | ||
query predicate summary(string csv) { | ||
exists( | ||
RelevantSummarizedCallable c, SummaryComponentStack input, SummaryComponentStack output, | ||
boolean preservesValue | ||
| | ||
c.relevantSummary(input, output, preservesValue) and | ||
csv = | ||
c.asPartialModel() + ";" + Public::getComponentStackCsv(input) + ";" + | ||
Public::getComponentStackCsv(output) + ";" + renderKind(preservesValue) | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This predicate and
isBaseCallableOrPrototype
will now be public (sinceDataFlowCallable
is), which I don't think we want. Instead it would be better to add them as top-level predicates inDataFlowPrivate.qll
.