Skip to content

Commit 873d355

Browse files
committed
Merge branch 'main' into static-useInstanceOf
2 parents 8262fbb + 912aa46 commit 873d355

File tree

156 files changed

+2807
-1101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+2807
-1101
lines changed

cpp/ql/src/Security/CWE/CWE-022/TaintedPath.ql

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import cpp
1818
import semmle.code.cpp.security.FunctionWithWrappers
19-
import semmle.code.cpp.security.Security
19+
import semmle.code.cpp.security.FlowSources
2020
import semmle.code.cpp.ir.IR
2121
import semmle.code.cpp.ir.dataflow.TaintTracking
2222
import DataFlow::PathGraph
@@ -47,12 +47,6 @@ class FileFunction extends FunctionWithWrappers {
4747
override predicate interestingArg(int arg) { arg = 0 }
4848
}
4949

50-
Expr asSourceExpr(DataFlow::Node node) {
51-
result = node.asConvertedExpr()
52-
or
53-
result = node.asDefiningArgument()
54-
}
55-
5650
Expr asSinkExpr(DataFlow::Node node) {
5751
result =
5852
node.asOperand()
@@ -89,7 +83,7 @@ predicate hasUpperBoundsCheck(Variable var) {
8983
class TaintedPathConfiguration extends TaintTracking::Configuration {
9084
TaintedPathConfiguration() { this = "TaintedPathConfiguration" }
9185

92-
override predicate isSource(DataFlow::Node node) { isUserInput(asSourceExpr(node), _) }
86+
override predicate isSource(DataFlow::Node node) { node instanceof FlowSource }
9387

9488
override predicate isSink(DataFlow::Node node) {
9589
exists(FileFunction fileFunction |
@@ -108,31 +102,16 @@ class TaintedPathConfiguration extends TaintTracking::Configuration {
108102
hasUpperBoundsCheck(checkedVar)
109103
)
110104
}
111-
112-
predicate hasFilteredFlowPath(DataFlow::PathNode source, DataFlow::PathNode sink) {
113-
this.hasFlowPath(source, sink) and
114-
// The use of `isUserInput` in `isSink` in combination with `asSourceExpr` causes
115-
// duplicate results. Filter these duplicates. The proper solution is to switch to
116-
// using `LocalFlowSource` and `RemoteFlowSource`, but this currently only supports
117-
// a subset of the cases supported by `isUserInput`.
118-
not exists(DataFlow::PathNode source2 |
119-
this.hasFlowPath(source2, sink) and
120-
asSourceExpr(source.getNode()) = asSourceExpr(source2.getNode())
121-
|
122-
not exists(source.getNode().asConvertedExpr()) and exists(source2.getNode().asConvertedExpr())
123-
)
124-
}
125105
}
126106

127107
from
128-
FileFunction fileFunction, Expr taintedArg, Expr taintSource, TaintedPathConfiguration cfg,
129-
DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode, string taintCause, string callChain
108+
FileFunction fileFunction, Expr taintedArg, FlowSource taintSource, TaintedPathConfiguration cfg,
109+
DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode, string callChain
130110
where
131111
taintedArg = asSinkExpr(sinkNode.getNode()) and
132112
fileFunction.outermostWrapperFunctionCall(taintedArg, callChain) and
133-
cfg.hasFilteredFlowPath(sourceNode, sinkNode) and
134-
taintSource = asSourceExpr(sourceNode.getNode()) and
135-
isUserInput(taintSource, taintCause)
113+
cfg.hasFlowPath(sourceNode, sinkNode) and
114+
taintSource = sourceNode.getNode()
136115
select taintedArg, sourceNode, sinkNode,
137116
"This argument to a file access function is derived from $@ and then passed to " + callChain + ".",
138-
taintSource, "user input (" + taintCause + ")"
117+
taintSource, "user input (" + taintSource.getSourceType() + ")"

cpp/ql/test/query-tests/Security/CWE/CWE-022/SAMATE/TaintedPath/TaintedPath.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ nodes
55
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection | semmle.label | data indirection |
66
subpaths
77
#select
8-
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | user input (fgets) |
8+
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | user input (string read by fgets) |

cpp/ql/test/query-tests/Security/CWE/CWE-022/semmle/tests/TaintedPath.expected

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ edges
22
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection |
33
| test.c:31:22:31:25 | argv | test.c:32:11:32:18 | fileName indirection |
44
| test.c:37:17:37:24 | scanf output argument | test.c:38:11:38:18 | fileName indirection |
5-
| test.c:43:17:43:24 | fileName | test.c:44:11:44:18 | fileName indirection |
65
| test.c:43:17:43:24 | scanf output argument | test.c:44:11:44:18 | fileName indirection |
76
nodes
87
| test.c:9:23:9:26 | argv | semmle.label | argv |
@@ -11,12 +10,11 @@ nodes
1110
| test.c:32:11:32:18 | fileName indirection | semmle.label | fileName indirection |
1211
| test.c:37:17:37:24 | scanf output argument | semmle.label | scanf output argument |
1312
| test.c:38:11:38:18 | fileName indirection | semmle.label | fileName indirection |
14-
| test.c:43:17:43:24 | fileName | semmle.label | fileName |
1513
| test.c:43:17:43:24 | scanf output argument | semmle.label | scanf output argument |
1614
| test.c:44:11:44:18 | fileName indirection | semmle.label | fileName indirection |
1715
subpaths
1816
#select
19-
| test.c:17:11:17:18 | fileName | test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:9:23:9:26 | argv | user input (argv) |
20-
| test.c:32:11:32:18 | fileName | test.c:31:22:31:25 | argv | test.c:32:11:32:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:31:22:31:25 | argv | user input (argv) |
21-
| test.c:38:11:38:18 | fileName | test.c:37:17:37:24 | scanf output argument | test.c:38:11:38:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:37:17:37:24 | fileName | user input (scanf) |
22-
| test.c:44:11:44:18 | fileName | test.c:43:17:43:24 | fileName | test.c:44:11:44:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:43:17:43:24 | fileName | user input (scanf) |
17+
| test.c:17:11:17:18 | fileName | test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:9:23:9:26 | argv | user input (a command-line argument) |
18+
| test.c:32:11:32:18 | fileName | test.c:31:22:31:25 | argv | test.c:32:11:32:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:31:22:31:25 | argv | user input (a command-line argument) |
19+
| test.c:38:11:38:18 | fileName | test.c:37:17:37:24 | scanf output argument | test.c:38:11:38:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:37:17:37:24 | scanf output argument | user input (value read by scanf) |
20+
| test.c:44:11:44:18 | fileName | test.c:43:17:43:24 | scanf output argument | test.c:44:11:44:18 | fileName indirection | This argument to a file access function is derived from $@ and then passed to fopen(filename). | test.c:43:17:43:24 | scanf output argument | user input (value read by scanf) |

csharp/ql/lib/ext/generated/dotnet_runtime.model.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10195,7 +10195,7 @@ extensions:
1019510195

1019610196
- addsTo:
1019710197
pack: codeql/csharp-all
10198-
extensible: extNegativeSummaryModel
10198+
extensible: extNeutralModel
1019910199
data:
1020010200
- ["AssemblyStripper", "AssemblyStripper", "StripAssembly", "(System.String,System.String)", "generated"]
1020110201
- ["Generators", "EventSourceGenerator", "Execute", "(Microsoft.CodeAnalysis.GeneratorExecutionContext)", "generated"]

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* `namespace; type; subtypes; name; signature; ext; input; kind; provenance`
1212
* - Summaries:
1313
* `namespace; type; subtypes; name; signature; ext; input; output; kind; provenance`
14-
* - Negative Summaries:
14+
* - Neutrals:
1515
* `namespace; type; name; signature; provenance`
16-
* A negative summary is used to indicate that there is no flow via a callable.
16+
* A neutral is used to indicate that there is no flow via a callable.
1717
*
1818
* The interpretation of a row is similar to API-graphs with a left-to-right
1919
* reading.
@@ -132,30 +132,12 @@ private class SummaryModelCsvInternal extends Unit {
132132
abstract predicate row(string row);
133133
}
134134

135-
/**
136-
* DEPRECATED: Define negative summary models as data extensions instead.
137-
*
138-
* A unit class for adding additional negative summary model rows.
139-
*
140-
* Extend this class to add additional negative summary definitions.
141-
*/
142-
deprecated class NegativeSummaryModelCsv = NegativeSummaryModelCsvInternal;
143-
144-
private class NegativeSummaryModelCsvInternal extends Unit {
145-
/** Holds if `row` specifies a negative summary definition. */
146-
abstract predicate row(string row);
147-
}
148-
149135
private predicate sourceModelInternal(string row) { any(SourceModelCsvInternal s).row(row) }
150136

151137
private predicate summaryModelInternal(string row) { any(SummaryModelCsvInternal s).row(row) }
152138

153139
private predicate sinkModelInternal(string row) { any(SinkModelCsvInternal s).row(row) }
154140

155-
private predicate negativeSummaryModelInternal(string row) {
156-
any(NegativeSummaryModelCsvInternal s).row(row)
157-
}
158-
159141
/**
160142
* Holds if a source model exists for the given parameters.
161143
*/
@@ -243,25 +225,16 @@ predicate summaryModel(
243225
extSummaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance)
244226
}
245227

246-
/** Holds if a summary model exists indicating there is no flow for the given parameters. */
247-
extensible predicate extNegativeSummaryModel(
228+
/** Holds if a model exists indicating there is no flow for the given parameters. */
229+
extensible predicate extNeutralModel(
248230
string namespace, string type, string name, string signature, string provenance
249231
);
250232

251-
/** Holds if a summary model exists indicating there is no flow for the given parameters. */
252-
predicate negativeSummaryModel(
233+
/** Holds if a model exists indicating there is no flow for the given parameters. */
234+
predicate neutralModel(
253235
string namespace, string type, string name, string signature, string provenance
254236
) {
255-
exists(string row |
256-
negativeSummaryModelInternal(row) and
257-
row.splitAt(";", 0) = namespace and
258-
row.splitAt(";", 1) = type and
259-
row.splitAt(";", 2) = name and
260-
row.splitAt(";", 3) = signature and
261-
row.splitAt(";", 4) = provenance
262-
)
263-
or
264-
extNegativeSummaryModel(namespace, type, name, signature, provenance)
237+
extNeutralModel(namespace, type, name, signature, provenance)
265238
}
266239

267240
private predicate relevantNamespace(string namespace) {
@@ -393,8 +366,6 @@ module ModelValidation {
393366
sinkModelInternal(row) and expect = 9 and pred = "sink"
394367
or
395368
summaryModelInternal(row) and expect = 10 and pred = "summary"
396-
or
397-
negativeSummaryModelInternal(row) and expect = 5 and pred = "negative summary"
398369
|
399370
exists(int cols |
400371
cols = 1 + max(int n | exists(row.splitAt(";", n))) and
@@ -418,9 +389,9 @@ module ModelValidation {
418389
summaryModel(namespace, type, _, name, signature, ext, _, _, _, provenance) and
419390
pred = "summary"
420391
or
421-
negativeSummaryModel(namespace, type, name, signature, provenance) and
392+
neutralModel(namespace, type, name, signature, provenance) and
422393
ext = "" and
423-
pred = "negative summary"
394+
pred = "neutral"
424395
|
425396
not namespace.regexpMatch("[a-zA-Z0-9_\\.]+") and
426397
result = "Dubious namespace \"" + namespace + "\" in " + pred + " model."
@@ -461,7 +432,7 @@ private predicate elementSpec(
461432
or
462433
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _)
463434
or
464-
negativeSummaryModel(namespace, type, name, signature, _) and ext = "" and subtypes = false
435+
neutralModel(namespace, type, name, signature, _) and ext = "" and subtypes = false
465436
}
466437

467438
private predicate elementSpec(
@@ -595,7 +566,7 @@ private Element interpretElement0(
595566
)
596567
}
597568

598-
/** Gets the source/sink/summary/negativesummary element corresponding to the supplied parameters. */
569+
/** Gets the source/sink/summary/neutral element corresponding to the supplied parameters. */
599570
Element interpretElement(
600571
string namespace, string type, boolean subtypes, string name, string signature, string ext
601572
) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,8 +2321,8 @@ module Csv {
23212321
)
23222322
}
23232323

2324-
/** Computes the first 4 columns for negative CSV rows of `c`. */
2325-
string asPartialNegativeModel(DotNet::Callable c) {
2324+
/** Computes the first 4 columns for neutral CSV rows of `c`. */
2325+
string asPartialNeutralModel(DotNet::Callable c) {
23262326
exists(string namespace, string type, string name, string parameters |
23272327
partialModel(c, namespace, type, name, parameters) and
23282328
result =

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ module Public {
246246
predicate isAutoGenerated() { none() }
247247
}
248248

249-
/** A callable with a flow summary stating there is no flow via the callable. */
250-
class NegativeSummarizedCallable extends SummarizedCallableBase {
251-
NegativeSummarizedCallable() { negativeSummaryElement(this, _) }
249+
/** A callable where there is no flow via the callable. */
250+
class NeutralCallable extends SummarizedCallableBase {
251+
NeutralCallable() { neutralElement(this, _) }
252252

253253
/**
254-
* Holds if the negative summary is auto generated.
254+
* Holds if the neutral is auto generated.
255255
*/
256-
predicate isAutoGenerated() { negativeSummaryElement(this, true) }
256+
predicate isAutoGenerated() { neutralElement(this, true) }
257257
}
258258
}
259259

@@ -1161,9 +1161,9 @@ module Private {
11611161
string toString() { result = super.toString() }
11621162
}
11631163

1164-
/** A flow summary to include in the `negativeSummary/1` query predicate. */
1165-
abstract class RelevantNegativeSummarizedCallable instanceof NegativeSummarizedCallable {
1166-
/** Gets the string representation of this callable used by `summary/1`. */
1164+
/** A model to include in the `neutral/1` query predicate. */
1165+
abstract class RelevantNeutralCallable instanceof NeutralCallable {
1166+
/** Gets the string representation of this callable used by `neutral/1`. */
11671167
abstract string getCallableCsv();
11681168

11691169
string toString() { result = super.toString() }
@@ -1180,13 +1180,13 @@ module Private {
11801180
if c.isAutoGenerated() then result = "generated" else result = "manual"
11811181
}
11821182

1183-
private string renderProvenanceNegative(NegativeSummarizedCallable c) {
1183+
private string renderProvenanceNeutral(NeutralCallable c) {
11841184
if c.isAutoGenerated() then result = "generated" else result = "manual"
11851185
}
11861186

11871187
/**
11881188
* A query predicate for outputting flow summaries in semi-colon separated format in QL tests.
1189-
* The syntax is: "namespace;type;overrides;name;signature;ext;inputspec;outputspec;kind;provenance"",
1189+
* The syntax is: "namespace;type;overrides;name;signature;ext;inputspec;outputspec;kind;provenance",
11901190
* ext is hardcoded to empty.
11911191
*/
11921192
query predicate summary(string csv) {
@@ -1205,14 +1205,14 @@ module Private {
12051205
}
12061206

12071207
/**
1208-
* Holds if a negative flow summary `csv` exists (semi-colon separated format). Used for testing purposes.
1208+
* Holds if a neutral model `csv` exists (semi-colon separated format). Used for testing purposes.
12091209
* The syntax is: "namespace;type;name;signature;provenance"",
12101210
*/
1211-
query predicate negativeSummary(string csv) {
1212-
exists(RelevantNegativeSummarizedCallable c |
1211+
query predicate neutral(string csv) {
1212+
exists(RelevantNeutralCallable c |
12131213
csv =
12141214
c.getCallableCsv() // Callable information
1215-
+ renderProvenanceNegative(c) // provenance
1215+
+ renderProvenanceNeutral(c) // provenance
12161216
)
12171217
}
12181218
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ predicate summaryElement(Callable c, string input, string output, string kind, b
121121
}
122122

123123
/**
124-
* Holds if a negative flow summary exists for `c`, which means that there is no
125-
* flow through `c`. The flag `generated` states whether the summary is autogenerated.
124+
* Holds if a neutral model exists for `c`, which means that there is no
125+
* flow through `c`. The flag `generated` states whether the neutral model is autogenerated.
126126
*/
127-
predicate negativeSummaryElement(Callable c, boolean generated) {
127+
predicate neutralElement(Callable c, boolean generated) {
128128
exists(string namespace, string type, string name, string signature, string provenance |
129-
negativeSummaryModel(namespace, type, name, signature, provenance) and
129+
neutralModel(namespace, type, name, signature, provenance) and
130130
generated = isGenerated(provenance) and
131131
c = interpretElement(namespace, type, false, name, signature, "")
132132
)

csharp/ql/src/Telemetry/SupportedExternalApis.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private predicate relevant(ExternalApi api) {
1515
not api.isUninteresting() and
1616
(
1717
api.isSupported() or
18-
api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
18+
api instanceof FlowSummaryImpl::Public::NeutralCallable
1919
)
2020
}
2121

csharp/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private import ExternalApi
1414
private predicate relevant(ExternalApi api) {
1515
not api.isUninteresting() and
1616
not api.isSupported() and
17-
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
17+
not api instanceof FlowSummaryImpl::Public::NeutralCallable
1818
}
1919

2020
from string info, int usages

0 commit comments

Comments
 (0)