Skip to content

Commit

Permalink
C#: Ignore the content of the subtypes column for MaD models and defa…
Browse files Browse the repository at this point in the history
…ult it to true.
  • Loading branch information
michaelnebel committed Nov 22, 2024
1 parent faabc99 commit ca5b51b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
*/

import csharp
import ExternalFlowExtensions
private import ExternalFlowExtensions as ExternalFlowExtensions
private import DataFlowDispatch
private import DataFlowPrivate
private import DataFlowPublic
Expand All @@ -102,6 +102,35 @@ private import semmle.code.csharp.frameworks.System
private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax
private import codeql.mad.ModelValidation as SharedModelVal

private predicate sourceModel(
string namespace, string type, boolean subtypes, string name, string signature, string ext,
string output, string kind, string provenance, QlBuiltins::ExtensionId madId
) {
subtypes = true and
ExternalFlowExtensions::sourceModel(namespace, type, _, name, signature, ext, output, kind,
provenance, madId)
}

private predicate sinkModel(
string namespace, string type, boolean subtypes, string name, string signature, string ext,
string input, string kind, string provenance, QlBuiltins::ExtensionId madId
) {
subtypes = true and
ExternalFlowExtensions::sinkModel(namespace, type, _, name, signature, ext, input, kind,
provenance, madId)
}

private predicate summaryModel(
string namespace, string type, boolean subtypes, string name, string signature, string ext,
string input, string output, string kind, string provenance, QlBuiltins::ExtensionId madId
) {
subtypes = true and
ExternalFlowExtensions::summaryModel(namespace, type, _, name, signature, ext, input, output,
kind, provenance, madId)
}

private predicate neutralModel = ExternalFlowExtensions::neutralModel/6;

/**
* Holds if the given extension tuple `madId` should pretty-print as `model`.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ private import DataFlowImplSpecific as DataFlowImplSpecific
private import DataFlowImplSpecific::Private
private import DataFlowImplSpecific::Public
private import semmle.code.csharp.Unification
private import semmle.code.csharp.dataflow.internal.ExternalFlowExtensions as ExternalFlowExtensions
private import semmle.code.csharp.dataflow.internal.ExternalFlow

module Input implements InputSig<Location, DataFlowImplSpecific::CsharpDataFlow> {
Expand Down Expand Up @@ -198,7 +199,8 @@ module SourceSinkInterpretationInput implements
string namespace, string type, boolean subtypes, string name, string signature, string ext,
QlBuiltins::ExtensionId madId
|
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance, madId) and
ExternalFlowExtensions::sourceModel(namespace, type, _, name, signature, ext, output, kind,
provenance, madId) and
model = "MaD:" + madId.toString() and
e = interpretElement(namespace, type, subtypes, name, signature, ext)
)
Expand All @@ -211,7 +213,8 @@ module SourceSinkInterpretationInput implements
string namespace, string type, boolean subtypes, string name, string signature, string ext,
QlBuiltins::ExtensionId madId
|
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, madId) and
ExternalFlowExtensions::sinkModel(namespace, type, _, name, signature, ext, input, kind,
provenance, madId) and
model = "MaD:" + madId.toString() and
e = interpretElement(namespace, type, subtypes, name, signature, ext)
)
Expand Down
1 change: 1 addition & 0 deletions csharp/ql/src/utils/modelconverter/InterpretModel.qll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csharp
import semmle.code.csharp.dataflow.internal.ExternalFlowExtensions
import semmle.code.csharp.dataflow.internal.ExternalFlow

bindingset[namespace0, type0, name0, signature0]
Expand Down

0 comments on commit ca5b51b

Please sign in to comment.