Skip to content

Commit cec5045

Browse files
committed
Merge branch 'main' into erb
2 parents 676327d + 68e513c commit cec5045

File tree

402 files changed

+24856
-12307
lines changed

Some content is hidden

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

402 files changed

+24856
-12307
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/{src,lib,test}/**/*.{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/js-ml-tests.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ defaults:
2323
working-directory: javascript/ql/experimental/adaptivethreatmodeling
2424

2525
jobs:
26-
qlformat:
27-
name: Check QL formatting
28-
runs-on: ubuntu-latest
29-
steps:
30-
- uses: actions/checkout@v3
31-
32-
- uses: ./.github/actions/fetch-codeql
33-
34-
- name: Check QL formatting
35-
run: |
36-
find . "(" -name "*.ql" -or -name "*.qll" ")" -print0 | \
37-
xargs -0 codeql query format --check-only
38-
3926
qlcompile:
4027
name: Check QL compilation
4128
runs-on: ubuntu-latest

.github/workflows/ruby-qltest.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ defaults:
2828
working-directory: ruby
2929

3030
jobs:
31-
qlformat:
32-
runs-on: ubuntu-latest
33-
steps:
34-
- uses: actions/checkout@v3
35-
- uses: ./.github/actions/fetch-codeql
36-
- name: Check QL formatting
37-
run: find ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 codeql query format --check-only
3831
qlcompile:
3932
runs-on: ubuntu-latest
4033
steps:

.github/workflows/swift.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,9 @@ jobs:
112112
with:
113113
name: swift-generated-cpp-files
114114
path: swift/generated-cpp-files/**
115-
qlformat:
115+
database-upgrade-scripts:
116116
runs-on: ubuntu-latest
117-
needs: changes
118-
if: ${{ needs.changes.outputs.ql == 'true' }}
119117
steps:
120118
- uses: actions/checkout@v3
121119
- uses: ./.github/actions/fetch-codeql
122-
- name: Check QL formatting
123-
run: find swift/ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 codeql query format --check-only
120+
- uses: ./swift/actions/database-upgrade-scripts

config/identical-files.json

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll"
9595
],
9696
"Model as Data Generation Java/C# - CaptureModels": [
97-
"java/ql/src/utils/model-generator/internal/CaptureModels.qll",
98-
"csharp/ql/src/utils/model-generator/internal/CaptureModels.qll"
97+
"java/ql/src/utils/modelgenerator/internal/CaptureModels.qll",
98+
"csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll"
9999
],
100100
"Sign Java/C#": [
101101
"java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/Sign.qll",
@@ -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) {

0 commit comments

Comments
 (0)