Skip to content

Commit de76df3

Browse files
committed
C#: Only use generated summaries, if no handwritten model exist for a particular dataflow callable.
1 parent 30dc4ae commit de76df3

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ module Private {
881881
summaryElement(this, inSpec, outSpec, kind, false)
882882
or
883883
summaryElement(this, inSpec, outSpec, kind, true) and
884-
not summaryElement(this, inSpec, outSpec, kind, false)
884+
not summaryElement(this, _, _, _, false)
885885
}
886886

887887
override predicate propagatesFlow(

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,10 @@ module Private {
806806
module External {
807807
/** Holds if `spec` is a relevant external specification. */
808808
private predicate relevantSpec(string spec) {
809-
summaryElement(_, spec, _, _) or
810-
summaryElement(_, _, spec, _) or
811-
sourceElement(_, spec, _) or
812-
sinkElement(_, spec, _)
809+
summaryElement(_, spec, _, _, _) or
810+
summaryElement(_, _, spec, _, _) or
811+
sourceElement(_, spec, _, _) or
812+
sinkElement(_, spec, _, _)
813813
}
814814

815815
private class AccessPathRange extends AccessPath::Range {
@@ -875,13 +875,20 @@ module Private {
875875
}
876876

877877
private class SummarizedCallableExternal extends SummarizedCallable {
878-
SummarizedCallableExternal() { summaryElement(this, _, _, _) }
878+
SummarizedCallableExternal() { summaryElement(this, _, _, _, _) }
879+
880+
private predicate relevantSummaryElement(AccessPath inSpec, AccessPath outSpec, string kind) {
881+
summaryElement(this, inSpec, outSpec, kind, false)
882+
or
883+
summaryElement(this, inSpec, outSpec, kind, true) and
884+
not summaryElement(this, _, _, _, false)
885+
}
879886

880887
override predicate propagatesFlow(
881888
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
882889
) {
883890
exists(AccessPath inSpec, AccessPath outSpec, string kind |
884-
summaryElement(this, inSpec, outSpec, kind) and
891+
this.relevantSummaryElement(inSpec, outSpec, kind) and
885892
interpretSpec(inSpec, input) and
886893
interpretSpec(outSpec, output)
887894
|
@@ -910,7 +917,7 @@ module Private {
910917

911918
private predicate sourceElementRef(InterpretNode ref, AccessPath output, string kind) {
912919
exists(SourceOrSinkElement e |
913-
sourceElement(e, output, kind) and
920+
sourceElement(e, output, kind, _) and
914921
if outputNeedsReference(output.getToken(0))
915922
then e = ref.getCallTarget()
916923
else e = ref.asElement()
@@ -919,7 +926,7 @@ module Private {
919926

920927
private predicate sinkElementRef(InterpretNode ref, AccessPath input, string kind) {
921928
exists(SourceOrSinkElement e |
922-
sinkElement(e, input, kind) and
929+
sinkElement(e, input, kind, _) and
923930
if inputNeedsReference(input.getToken(0))
924931
then e = ref.getCallTarget()
925932
else e = ref.asElement()

ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,10 @@ module Private {
806806
module External {
807807
/** Holds if `spec` is a relevant external specification. */
808808
private predicate relevantSpec(string spec) {
809-
summaryElement(_, spec, _, _) or
810-
summaryElement(_, _, spec, _) or
811-
sourceElement(_, spec, _) or
812-
sinkElement(_, spec, _)
809+
summaryElement(_, spec, _, _, _) or
810+
summaryElement(_, _, spec, _, _) or
811+
sourceElement(_, spec, _, _) or
812+
sinkElement(_, spec, _, _)
813813
}
814814

815815
private class AccessPathRange extends AccessPath::Range {
@@ -875,13 +875,20 @@ module Private {
875875
}
876876

877877
private class SummarizedCallableExternal extends SummarizedCallable {
878-
SummarizedCallableExternal() { summaryElement(this, _, _, _) }
878+
SummarizedCallableExternal() { summaryElement(this, _, _, _, _) }
879+
880+
private predicate relevantSummaryElement(AccessPath inSpec, AccessPath outSpec, string kind) {
881+
summaryElement(this, inSpec, outSpec, kind, false)
882+
or
883+
summaryElement(this, inSpec, outSpec, kind, true) and
884+
not summaryElement(this, _, _, _, false)
885+
}
879886

880887
override predicate propagatesFlow(
881888
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
882889
) {
883890
exists(AccessPath inSpec, AccessPath outSpec, string kind |
884-
summaryElement(this, inSpec, outSpec, kind) and
891+
this.relevantSummaryElement(inSpec, outSpec, kind) and
885892
interpretSpec(inSpec, input) and
886893
interpretSpec(outSpec, output)
887894
|
@@ -910,7 +917,7 @@ module Private {
910917

911918
private predicate sourceElementRef(InterpretNode ref, AccessPath output, string kind) {
912919
exists(SourceOrSinkElement e |
913-
sourceElement(e, output, kind) and
920+
sourceElement(e, output, kind, _) and
914921
if outputNeedsReference(output.getToken(0))
915922
then e = ref.getCallTarget()
916923
else e = ref.asElement()
@@ -919,7 +926,7 @@ module Private {
919926

920927
private predicate sinkElementRef(InterpretNode ref, AccessPath input, string kind) {
921928
exists(SourceOrSinkElement e |
922-
sinkElement(e, input, kind) and
929+
sinkElement(e, input, kind, _) and
923930
if inputNeedsReference(input.getToken(0))
924931
then e = ref.getCallTarget()
925932
else e = ref.asElement()

0 commit comments

Comments
 (0)