Skip to content

Commit 3260c81

Browse files
authored
Merge branch 'github:main' into main
2 parents 5ea03b1 + d285700 commit 3260c81

File tree

242 files changed

+22230
-8084
lines changed

Some content is hidden

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

242 files changed

+22230
-8084
lines changed

.github/workflows/compile-queries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
channel: 'release'
4848
- name: check formatting
49-
run: codeql query format */ql/**/*.{qll,ql} --check-only
49+
run: find */ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 codeql query format --check-only
5050
- name: compile queries - check-only
5151
# run with --check-only if running in a PR (github.sha != main)
5252
if : ${{ github.event_name == 'pull_request' }}

.github/workflows/swift.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,10 @@ jobs:
111111
- uses: actions/upload-artifact@v3
112112
with:
113113
name: swift-generated-cpp-files
114-
path: swift/generated-cpp-files/**
114+
path: swift/generated-cpp-files/**
115+
database-upgrade-scripts:
116+
runs-on: ubuntu-latest
117+
steps:
118+
- uses: actions/checkout@v3
119+
- uses: ./.github/actions/fetch-codeql
120+
- uses: ./swift/actions/database-upgrade-scripts

config/identical-files.json

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -486,40 +486,6 @@
486486
"python/ql/lib/semmle/python/security/internal/SensitiveDataHeuristics.qll",
487487
"ruby/ql/lib/codeql/ruby/security/internal/SensitiveDataHeuristics.qll"
488488
],
489-
"ReDoS Util Python/JS/Ruby/Java": [
490-
"javascript/ql/lib/semmle/javascript/security/regexp/NfaUtils.qll",
491-
"python/ql/lib/semmle/python/security/regexp/NfaUtils.qll",
492-
"ruby/ql/lib/codeql/ruby/security/regexp/NfaUtils.qll",
493-
"java/ql/lib/semmle/code/java/security/regexp/NfaUtils.qll"
494-
],
495-
"ReDoS Exponential Python/JS/Ruby/Java": [
496-
"javascript/ql/lib/semmle/javascript/security/regexp/ExponentialBackTracking.qll",
497-
"python/ql/lib/semmle/python/security/regexp/ExponentialBackTracking.qll",
498-
"ruby/ql/lib/codeql/ruby/security/regexp/ExponentialBackTracking.qll",
499-
"java/ql/lib/semmle/code/java/security/regexp/ExponentialBackTracking.qll"
500-
],
501-
"ReDoS Polynomial Python/JS/Ruby/Java": [
502-
"javascript/ql/lib/semmle/javascript/security/regexp/SuperlinearBackTracking.qll",
503-
"python/ql/lib/semmle/python/security/regexp/SuperlinearBackTracking.qll",
504-
"ruby/ql/lib/codeql/ruby/security/regexp/SuperlinearBackTracking.qll",
505-
"java/ql/lib/semmle/code/java/security/regexp/SuperlinearBackTracking.qll"
506-
],
507-
"RegexpMatching Python/JS/Ruby": [
508-
"javascript/ql/lib/semmle/javascript/security/regexp/RegexpMatching.qll",
509-
"python/ql/lib/semmle/python/security/regexp/RegexpMatching.qll",
510-
"ruby/ql/lib/codeql/ruby/security/regexp/RegexpMatching.qll"
511-
],
512-
"BadTagFilterQuery Python/JS/Ruby": [
513-
"javascript/ql/lib/semmle/javascript/security/BadTagFilterQuery.qll",
514-
"python/ql/lib/semmle/python/security/BadTagFilterQuery.qll",
515-
"ruby/ql/lib/codeql/ruby/security/BadTagFilterQuery.qll"
516-
],
517-
"OverlyLargeRange Python/JS/Ruby/Java": [
518-
"javascript/ql/lib/semmle/javascript/security/OverlyLargeRangeQuery.qll",
519-
"python/ql/lib/semmle/python/security/OverlyLargeRangeQuery.qll",
520-
"ruby/ql/lib/codeql/ruby/security/OverlyLargeRangeQuery.qll",
521-
"java/ql/lib/semmle/code/java/security/OverlyLargeRangeQuery.qll"
522-
],
523489
"CFG": [
524490
"csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImplShared.qll",
525491
"ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImplShared.qll",

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ module Consistency {
136136
msg = "Local flow step does not preserve enclosing callable."
137137
}
138138

139+
query predicate readStepIsLocal(Node n1, Node n2, string msg) {
140+
readStep(n1, _, n2) and
141+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
142+
msg = "Read step does not preserve enclosing callable."
143+
}
144+
145+
query predicate storeStepIsLocal(Node n1, Node n2, string msg) {
146+
storeStep(n1, _, n2) and
147+
nodeGetEnclosingCallable(n1) != nodeGetEnclosingCallable(n2) and
148+
msg = "Store step does not preserve enclosing callable."
149+
}
150+
139151
private DataFlowType typeRepr() { result = getNodeType(_) }
140152

141153
query predicate compatibleTypesReflexive(DataFlowType t, string msg) {

cpp/ql/lib/semmle/code/cpp/models/implementations/StdString.qll

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ private class StdBasicString extends ClassTemplateInstantiation {
1616
}
1717

1818
/**
19-
* Additional model for `std::string` constructors that reference the character
20-
* type of the container, or an iterator. For example construction from
21-
* iterators:
22-
* ```
23-
* std::string b(a.begin(), a.end());
24-
* ```
19+
* The `std::basic_string::iterator` declaration.
2520
*/
26-
private class StdStringConstructor extends Constructor, TaintFunction {
27-
StdStringConstructor() { this.getDeclaringType() instanceof StdBasicString }
21+
private class StdBasicStringIterator extends Iterator, Type {
22+
StdBasicStringIterator() {
23+
this.getEnclosingElement() instanceof StdBasicString and this.hasName("iterator")
24+
}
25+
}
2826

27+
/**
28+
* A `std::string` function for which taint should be propagated.
29+
*/
30+
abstract private class StdStringTaintFunction extends TaintFunction {
2931
/**
3032
* Gets the index of a parameter to this function that is a string (or
3133
* character).
3234
*/
33-
int getAStringParameterIndex() {
35+
final int getAStringParameterIndex() {
3436
exists(Type paramType | paramType = this.getParameter(result).getUnspecifiedType() |
3537
// e.g. `std::basic_string::CharT *`
3638
paramType instanceof PointerType
@@ -41,15 +43,28 @@ private class StdStringConstructor extends Constructor, TaintFunction {
4143
this.getDeclaringType().getTemplateArgument(2).(Type).getUnspecifiedType()
4244
or
4345
// i.e. `std::basic_string::CharT`
44-
this.getParameter(result).getUnspecifiedType() =
45-
this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType()
46+
paramType = this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType()
4647
)
4748
}
4849

4950
/**
5051
* Gets the index of a parameter to this function that is an iterator.
5152
*/
52-
int getAnIteratorParameterIndex() { this.getParameter(result).getType() instanceof Iterator }
53+
final int getAnIteratorParameterIndex() {
54+
this.getParameter(result).getType() instanceof Iterator
55+
}
56+
}
57+
58+
/**
59+
* Additional model for `std::string` constructors that reference the character
60+
* type of the container, or an iterator. For example construction from
61+
* iterators:
62+
* ```
63+
* std::string b(a.begin(), a.end());
64+
* ```
65+
*/
66+
private class StdStringConstructor extends Constructor, StdStringTaintFunction {
67+
StdStringConstructor() { this.getDeclaringType() instanceof StdBasicString }
5368

5469
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
5570
// taint flow from any parameter of the value type to the returned object
@@ -68,7 +83,7 @@ private class StdStringConstructor extends Constructor, TaintFunction {
6883
/**
6984
* The `std::string` function `c_str`.
7085
*/
71-
private class StdStringCStr extends TaintFunction {
86+
private class StdStringCStr extends StdStringTaintFunction {
7287
StdStringCStr() { this.getClassAndName("c_str") instanceof StdBasicString }
7388

7489
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -81,7 +96,7 @@ private class StdStringCStr extends TaintFunction {
8196
/**
8297
* The `std::string` function `data`.
8398
*/
84-
private class StdStringData extends TaintFunction {
99+
private class StdStringData extends StdStringTaintFunction {
85100
StdStringData() { this.getClassAndName("data") instanceof StdBasicString }
86101

87102
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -99,7 +114,7 @@ private class StdStringData extends TaintFunction {
99114
/**
100115
* The `std::string` function `push_back`.
101116
*/
102-
private class StdStringPush extends TaintFunction {
117+
private class StdStringPush extends StdStringTaintFunction {
103118
StdStringPush() { this.getClassAndName("push_back") instanceof StdBasicString }
104119

105120
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -112,7 +127,7 @@ private class StdStringPush extends TaintFunction {
112127
/**
113128
* The `std::string` functions `front` and `back`.
114129
*/
115-
private class StdStringFrontBack extends TaintFunction {
130+
private class StdStringFrontBack extends StdStringTaintFunction {
116131
StdStringFrontBack() { this.getClassAndName(["front", "back"]) instanceof StdBasicString }
117132

118133
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -125,7 +140,7 @@ private class StdStringFrontBack extends TaintFunction {
125140
/**
126141
* The (non-member) `std::string` function `operator+`.
127142
*/
128-
private class StdStringPlus extends TaintFunction {
143+
private class StdStringPlus extends StdStringTaintFunction {
129144
StdStringPlus() {
130145
this.hasQualifiedName(["std", "bsl"], "operator+") and
131146
this.getUnspecifiedType() instanceof StdBasicString
@@ -142,31 +157,15 @@ private class StdStringPlus extends TaintFunction {
142157
}
143158

144159
/**
145-
* The `std::string` functions `operator+=`, `append`, `insert` and
146-
* `replace`. All of these functions combine the existing string
147-
* with a new string (or character) from one of the arguments.
160+
* The `std::string` functions `operator+=`, `append` and `replace`.
161+
* All of these functions combine the existing string with a new
162+
* string (or character) from one of the arguments.
148163
*/
149-
private class StdStringAppend extends TaintFunction {
164+
private class StdStringAppend extends StdStringTaintFunction {
150165
StdStringAppend() {
151-
this.getClassAndName(["operator+=", "append", "insert", "replace"]) instanceof StdBasicString
152-
}
153-
154-
/**
155-
* Gets the index of a parameter to this function that is a string (or
156-
* character).
157-
*/
158-
int getAStringParameterIndex() {
159-
this.getParameter(result).getType() instanceof PointerType or // e.g. `std::basic_string::CharT *`
160-
this.getParameter(result).getType() instanceof ReferenceType or // e.g. `std::basic_string &`
161-
this.getParameter(result).getUnspecifiedType() =
162-
this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType() // i.e. `std::basic_string::CharT`
166+
this.getClassAndName(["operator+=", "append", "replace"]) instanceof StdBasicString
163167
}
164168

165-
/**
166-
* Gets the index of a parameter to this function that is an iterator.
167-
*/
168-
int getAnIteratorParameterIndex() { this.getParameter(result).getType() instanceof Iterator }
169-
170169
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
171170
// flow from string and parameter to string (qualifier) and return value
172171
(
@@ -187,26 +186,42 @@ private class StdStringAppend extends TaintFunction {
187186
}
188187

189188
/**
190-
* The standard function `std::string.assign`.
189+
* The `std::string` function `insert`.
191190
*/
192-
private class StdStringAssign extends TaintFunction {
193-
StdStringAssign() { this.getClassAndName("assign") instanceof StdBasicString }
191+
private class StdStringInsert extends StdStringTaintFunction {
192+
StdStringInsert() { this.getClassAndName("insert") instanceof StdBasicString }
194193

195194
/**
196-
* Gets the index of a parameter to this function that is a string (or
197-
* character).
195+
* Holds if the return type is an iterator.
198196
*/
199-
int getAStringParameterIndex() {
200-
this.getParameter(result).getType() instanceof PointerType or // e.g. `std::basic_string::CharT *`
201-
this.getParameter(result).getType() instanceof ReferenceType or // e.g. `std::basic_string &`
202-
this.getParameter(result).getUnspecifiedType() =
203-
this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType() // i.e. `std::basic_string::CharT`
197+
predicate hasIteratorReturnValue() { this.getType() instanceof Iterator }
198+
199+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
200+
// flow from string and parameter to string (qualifier) and return value
201+
(
202+
input.isQualifierObject() or
203+
input.isParameterDeref(this.getAStringParameterIndex()) or
204+
input.isParameter(this.getAnIteratorParameterIndex())
205+
) and
206+
(
207+
output.isQualifierObject()
208+
or
209+
if this.hasIteratorReturnValue() then output.isReturnValue() else output.isReturnValueDeref()
210+
)
211+
or
212+
// reverse flow from returned reference to the qualifier (for writes to
213+
// the result)
214+
not this.hasIteratorReturnValue() and
215+
input.isReturnValueDeref() and
216+
output.isQualifierObject()
204217
}
218+
}
205219

206-
/**
207-
* Gets the index of a parameter to this function that is an iterator.
208-
*/
209-
int getAnIteratorParameterIndex() { this.getParameter(result).getType() instanceof Iterator }
220+
/**
221+
* The standard function `std::string.assign`.
222+
*/
223+
private class StdStringAssign extends StdStringTaintFunction {
224+
StdStringAssign() { this.getClassAndName("assign") instanceof StdBasicString }
210225

211226
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
212227
// flow from parameter to string itself (qualifier) and return value
@@ -229,7 +244,7 @@ private class StdStringAssign extends TaintFunction {
229244
/**
230245
* The standard function `std::string.copy`.
231246
*/
232-
private class StdStringCopy extends TaintFunction {
247+
private class StdStringCopy extends StdStringTaintFunction {
233248
StdStringCopy() { this.getClassAndName("copy") instanceof StdBasicString }
234249

235250
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -242,7 +257,7 @@ private class StdStringCopy extends TaintFunction {
242257
/**
243258
* The standard function `std::string.substr`.
244259
*/
245-
private class StdStringSubstr extends TaintFunction {
260+
private class StdStringSubstr extends StdStringTaintFunction {
246261
StdStringSubstr() { this.getClassAndName("substr") instanceof StdBasicString }
247262

248263
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -255,7 +270,7 @@ private class StdStringSubstr extends TaintFunction {
255270
/**
256271
* The `std::string` functions `at` and `operator[]`.
257272
*/
258-
private class StdStringAt extends TaintFunction {
273+
private class StdStringAt extends StdStringTaintFunction {
259274
StdStringAt() { this.getClassAndName(["at", "operator[]"]) instanceof StdBasicString }
260275

261276
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ uniqueNodeToString
66
missingToString
77
parameterCallable
88
localFlowIsLocal
9+
readStepIsLocal
10+
storeStepIsLocal
911
compatibleTypesReflexive
1012
unreachableNodeCCtx
1113
localCallNodes

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ uniqueNodeToString
2121
missingToString
2222
parameterCallable
2323
localFlowIsLocal
24+
readStepIsLocal
25+
storeStepIsLocal
2426
compatibleTypesReflexive
2527
unreachableNodeCCtx
2628
localCallNodes

cpp/ql/test/library-tests/dataflow/fields/dataflow-consistency.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ uniqueNodeToString
1212
missingToString
1313
parameterCallable
1414
localFlowIsLocal
15+
readStepIsLocal
16+
storeStepIsLocal
1517
compatibleTypesReflexive
1618
unreachableNodeCCtx
1719
localCallNodes

0 commit comments

Comments
 (0)