Skip to content

Commit c650b7c

Browse files
committed
Update shared library files for go to PR github#9867
Merge commit: c514c88
1 parent 2309b86 commit c650b7c

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ module Public {
240240
*/
241241
predicate isAutoGenerated() { none() }
242242
}
243+
244+
/** A callable with a flow summary stating there is no flow via the callable. */
245+
class NegativeSummarizedCallable extends SummarizedCallableBase {
246+
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
247+
248+
/**
249+
* Holds if the negative summary is auto generated.
250+
*/
251+
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
252+
}
243253
}
244254

245255
/**
@@ -1094,7 +1104,7 @@ module Private {
10941104

10951105
/** Provides a query predicate for outputting a set of relevant flow summaries. */
10961106
module TestOutput {
1097-
/** A flow summary to include in the `summary/3` query predicate. */
1107+
/** A flow summary to include in the `summary/1` query predicate. */
10981108
abstract class RelevantSummarizedCallable instanceof SummarizedCallable {
10991109
/** Gets the string representation of this callable used by `summary/1`. */
11001110
abstract string getCallableCsv();
@@ -1109,15 +1119,27 @@ module Private {
11091119
string toString() { result = super.toString() }
11101120
}
11111121

1122+
/** A flow summary to include in the `negativeSummary/1` query predicate. */
1123+
abstract class RelevantNegativeSummarizedCallable instanceof NegativeSummarizedCallable {
1124+
/** Gets the string representation of this callable used by `summary/1`. */
1125+
abstract string getCallableCsv();
1126+
1127+
string toString() { result = super.toString() }
1128+
}
1129+
11121130
/** Render the kind in the format used in flow summaries. */
11131131
private string renderKind(boolean preservesValue) {
11141132
preservesValue = true and result = "value"
11151133
or
11161134
preservesValue = false and result = "taint"
11171135
}
11181136

1119-
private string renderProvenance(RelevantSummarizedCallable c) {
1120-
if c.(SummarizedCallable).isAutoGenerated() then result = "generated" else result = "manual"
1137+
private string renderProvenance(SummarizedCallable c) {
1138+
if c.isAutoGenerated() then result = "generated" else result = "manual"
1139+
}
1140+
1141+
private string renderProvenanceNegative(NegativeSummarizedCallable c) {
1142+
if c.isAutoGenerated() then result = "generated" else result = "manual"
11211143
}
11221144

11231145
/**
@@ -1132,8 +1154,23 @@ module Private {
11321154
|
11331155
c.relevantSummary(input, output, preservesValue) and
11341156
csv =
1135-
c.getCallableCsv() + getComponentStackCsv(input) + ";" + getComponentStackCsv(output) +
1136-
";" + renderKind(preservesValue) + ";" + renderProvenance(c)
1157+
c.getCallableCsv() // Callable information
1158+
+ getComponentStackCsv(input) + ";" // input
1159+
+ getComponentStackCsv(output) + ";" // output
1160+
+ renderKind(preservesValue) + ";" // kind
1161+
+ renderProvenance(c) // provenance
1162+
)
1163+
}
1164+
1165+
/**
1166+
* Holds if a negative flow summary `csv` exists (semi-colon separated format). Used for testing purposes.
1167+
* The syntax is: "namespace;type;name;signature;provenance"",
1168+
*/
1169+
query predicate negativeSummary(string csv) {
1170+
exists(RelevantNegativeSummarizedCallable c |
1171+
csv =
1172+
c.getCallableCsv() // Callable information
1173+
+ renderProvenanceNegative(c) // provenance
11371174
)
11381175
}
11391176
}

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ predicate summaryElement(
7272
)
7373
}
7474

75+
/**
76+
* Holds if a negative flow summary exists for `c`, which means that there is no
77+
* flow through `c`. The flag `generated` states whether the summary is autogenerated.
78+
* Note. Negative flow summaries has not been implemented for Go.
79+
*/
80+
predicate negativeSummaryElement(SummarizedCallable c, boolean generated) { none() }
81+
7582
/** Gets the summary component for specification component `c`, if any. */
7683
bindingset[c]
7784
SummaryComponent interpretComponentSpecific(string c) {

0 commit comments

Comments
 (0)