Skip to content

Commit d3ff490

Browse files
committed
Merge branch 'main' into redsun82/swift-error-element
2 parents f5b198b + d567ab3 commit d3ff490

File tree

181 files changed

+2838
-1083
lines changed

Some content is hidden

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

181 files changed

+2838
-1083
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: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,4 @@ jobs:
111111
- uses: actions/upload-artifact@v3
112112
with:
113113
name: swift-generated-cpp-files
114-
path: swift/generated-cpp-files/**
115-
qlformat:
116-
runs-on: ubuntu-latest
117-
needs: changes
118-
if: ${{ needs.changes.outputs.ql == 'true' }}
119-
steps:
120-
- uses: actions/checkout@v3
121-
- 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
114+
path: swift/generated-cpp-files/**

config/identical-files.json

Lines changed: 2 additions & 2 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",

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

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@ 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+
* A `std::string` function for which taint should be propagated.
2520
*/
26-
private class StdStringConstructor extends Constructor, TaintFunction {
27-
StdStringConstructor() { this.getDeclaringType() instanceof StdBasicString }
28-
21+
abstract private class StdStringTaintFunction extends TaintFunction {
2922
/**
3023
* Gets the index of a parameter to this function that is a string (or
3124
* character).
3225
*/
33-
int getAStringParameterIndex() {
26+
final int getAStringParameterIndex() {
3427
exists(Type paramType | paramType = this.getParameter(result).getUnspecifiedType() |
3528
// e.g. `std::basic_string::CharT *`
3629
paramType instanceof PointerType
@@ -41,15 +34,28 @@ private class StdStringConstructor extends Constructor, TaintFunction {
4134
this.getDeclaringType().getTemplateArgument(2).(Type).getUnspecifiedType()
4235
or
4336
// i.e. `std::basic_string::CharT`
44-
this.getParameter(result).getUnspecifiedType() =
45-
this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType()
37+
paramType = this.getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType()
4638
)
4739
}
4840

4941
/**
5042
* Gets the index of a parameter to this function that is an iterator.
5143
*/
52-
int getAnIteratorParameterIndex() { this.getParameter(result).getType() instanceof Iterator }
44+
final int getAnIteratorParameterIndex() {
45+
this.getParameter(result).getType() instanceof Iterator
46+
}
47+
}
48+
49+
/**
50+
* Additional model for `std::string` constructors that reference the character
51+
* type of the container, or an iterator. For example construction from
52+
* iterators:
53+
* ```
54+
* std::string b(a.begin(), a.end());
55+
* ```
56+
*/
57+
private class StdStringConstructor extends Constructor, StdStringTaintFunction {
58+
StdStringConstructor() { this.getDeclaringType() instanceof StdBasicString }
5359

5460
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
5561
// taint flow from any parameter of the value type to the returned object
@@ -68,7 +74,7 @@ private class StdStringConstructor extends Constructor, TaintFunction {
6874
/**
6975
* The `std::string` function `c_str`.
7076
*/
71-
private class StdStringCStr extends TaintFunction {
77+
private class StdStringCStr extends StdStringTaintFunction {
7278
StdStringCStr() { this.getClassAndName("c_str") instanceof StdBasicString }
7379

7480
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -81,7 +87,7 @@ private class StdStringCStr extends TaintFunction {
8187
/**
8288
* The `std::string` function `data`.
8389
*/
84-
private class StdStringData extends TaintFunction {
90+
private class StdStringData extends StdStringTaintFunction {
8591
StdStringData() { this.getClassAndName("data") instanceof StdBasicString }
8692

8793
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -99,7 +105,7 @@ private class StdStringData extends TaintFunction {
99105
/**
100106
* The `std::string` function `push_back`.
101107
*/
102-
private class StdStringPush extends TaintFunction {
108+
private class StdStringPush extends StdStringTaintFunction {
103109
StdStringPush() { this.getClassAndName("push_back") instanceof StdBasicString }
104110

105111
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -112,7 +118,7 @@ private class StdStringPush extends TaintFunction {
112118
/**
113119
* The `std::string` functions `front` and `back`.
114120
*/
115-
private class StdStringFrontBack extends TaintFunction {
121+
private class StdStringFrontBack extends StdStringTaintFunction {
116122
StdStringFrontBack() { this.getClassAndName(["front", "back"]) instanceof StdBasicString }
117123

118124
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -125,7 +131,7 @@ private class StdStringFrontBack extends TaintFunction {
125131
/**
126132
* The (non-member) `std::string` function `operator+`.
127133
*/
128-
private class StdStringPlus extends TaintFunction {
134+
private class StdStringPlus extends StdStringTaintFunction {
129135
StdStringPlus() {
130136
this.hasQualifiedName(["std", "bsl"], "operator+") and
131137
this.getUnspecifiedType() instanceof StdBasicString
@@ -142,31 +148,15 @@ private class StdStringPlus extends TaintFunction {
142148
}
143149

144150
/**
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.
151+
* The `std::string` functions `operator+=`, `append` and `replace`.
152+
* All of these functions combine the existing string with a new
153+
* string (or character) from one of the arguments.
148154
*/
149-
private class StdStringAppend extends TaintFunction {
155+
private class StdStringAppend extends StdStringTaintFunction {
150156
StdStringAppend() {
151-
this.getClassAndName(["operator+=", "append", "insert", "replace"]) instanceof StdBasicString
157+
this.getClassAndName(["operator+=", "append", "replace"]) instanceof StdBasicString
152158
}
153159

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`
163-
}
164-
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-
170160
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
171161
// flow from string and parameter to string (qualifier) and return value
172162
(
@@ -187,26 +177,42 @@ private class StdStringAppend extends TaintFunction {
187177
}
188178

189179
/**
190-
* The standard function `std::string.assign`.
180+
* The `std::string` function `insert`.
191181
*/
192-
private class StdStringAssign extends TaintFunction {
193-
StdStringAssign() { this.getClassAndName("assign") instanceof StdBasicString }
182+
private class StdStringInsert extends StdStringTaintFunction {
183+
StdStringInsert() { this.getClassAndName("insert") instanceof StdBasicString }
194184

195185
/**
196-
* Gets the index of a parameter to this function that is a string (or
197-
* character).
186+
* Holds if the return type is an iterator.
198187
*/
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`
188+
predicate hasIteratorReturnValue() { this.getType() instanceof Iterator }
189+
190+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
191+
// flow from string and parameter to string (qualifier) and return value
192+
(
193+
input.isQualifierObject() or
194+
input.isParameterDeref(this.getAStringParameterIndex()) or
195+
input.isParameter(this.getAnIteratorParameterIndex())
196+
) and
197+
(
198+
output.isQualifierObject()
199+
or
200+
if this.hasIteratorReturnValue() then output.isReturnValue() else output.isReturnValueDeref()
201+
)
202+
or
203+
// reverse flow from returned reference to the qualifier (for writes to
204+
// the result)
205+
not this.hasIteratorReturnValue() and
206+
input.isReturnValueDeref() and
207+
output.isQualifierObject()
204208
}
209+
}
205210

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 }
211+
/**
212+
* The standard function `std::string.assign`.
213+
*/
214+
private class StdStringAssign extends StdStringTaintFunction {
215+
StdStringAssign() { this.getClassAndName("assign") instanceof StdBasicString }
210216

211217
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
212218
// flow from parameter to string itself (qualifier) and return value
@@ -229,7 +235,7 @@ private class StdStringAssign extends TaintFunction {
229235
/**
230236
* The standard function `std::string.copy`.
231237
*/
232-
private class StdStringCopy extends TaintFunction {
238+
private class StdStringCopy extends StdStringTaintFunction {
233239
StdStringCopy() { this.getClassAndName("copy") instanceof StdBasicString }
234240

235241
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -242,7 +248,7 @@ private class StdStringCopy extends TaintFunction {
242248
/**
243249
* The standard function `std::string.substr`.
244250
*/
245-
private class StdStringSubstr extends TaintFunction {
251+
private class StdStringSubstr extends StdStringTaintFunction {
246252
StdStringSubstr() { this.getClassAndName("substr") instanceof StdBasicString }
247253

248254
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -255,7 +261,7 @@ private class StdStringSubstr extends TaintFunction {
255261
/**
256262
* The `std::string` functions `at` and `operator[]`.
257263
*/
258-
private class StdStringAt extends TaintFunction {
264+
private class StdStringAt extends StdStringTaintFunction {
259265
StdStringAt() { this.getClassAndName(["at", "operator[]"]) instanceof StdBasicString }
260266

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

cpp/ql/test/library-tests/dataflow/taint-tests/bsd.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct sockaddr {
99
char* sa_data;
1010
};
1111

12-
int accept(int, const sockaddr*, int*);
12+
int accept(int, sockaddr*, int*);
1313

1414
void sink(sockaddr);
1515

@@ -20,5 +20,5 @@ void test_accept() {
2020
int a = accept(s, &addr, &size);
2121

2222
sink(a); // $ ast=17:11 ir SPURIOUS: ast=18:12
23-
sink(addr); // $ ast,ir
23+
sink(addr); // $ ast=17:11 ir SPURIOUS: ast=18:12
2424
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,14 @@
142142
| bsd.cpp:19:14:19:29 | sizeof(sockaddr) | bsd.cpp:20:29:20:32 | size | |
143143
| bsd.cpp:20:11:20:16 | call to accept | bsd.cpp:22:8:22:8 | a | |
144144
| bsd.cpp:20:18:20:18 | s | bsd.cpp:20:11:20:16 | call to accept | TAINT |
145+
| bsd.cpp:20:18:20:18 | s | bsd.cpp:20:21:20:25 | ref arg & ... | TAINT |
145146
| bsd.cpp:20:21:20:25 | & ... | bsd.cpp:20:11:20:16 | call to accept | TAINT |
147+
| bsd.cpp:20:21:20:25 | & ... | bsd.cpp:20:21:20:25 | ref arg & ... | TAINT |
148+
| bsd.cpp:20:21:20:25 | ref arg & ... | bsd.cpp:20:22:20:25 | addr [inner post update] | |
149+
| bsd.cpp:20:21:20:25 | ref arg & ... | bsd.cpp:23:8:23:11 | addr | |
146150
| bsd.cpp:20:22:20:25 | addr | bsd.cpp:20:11:20:16 | call to accept | TAINT |
147151
| bsd.cpp:20:22:20:25 | addr | bsd.cpp:20:21:20:25 | & ... | |
152+
| bsd.cpp:20:22:20:25 | addr | bsd.cpp:20:21:20:25 | ref arg & ... | TAINT |
148153
| bsd.cpp:20:28:20:32 | ref arg & ... | bsd.cpp:20:29:20:32 | size [inner post update] | |
149154
| bsd.cpp:20:29:20:32 | size | bsd.cpp:20:28:20:32 | & ... | |
150155
| constructor_delegation.cpp:8:2:8:8 | this | constructor_delegation.cpp:8:20:8:24 | constructor init of field x [pre-this] | |

csharp/documentation/library-coverage/coverage.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Microsoft.Win32,,,8,,,,,,,,,,,,8,
2424
MySql.Data.MySqlClient,48,,,,,,,,,,48,,,,,
2525
Newtonsoft.Json,,,91,,,,,,,,,,,,73,18
2626
ServiceStack,194,,7,27,,,,,,75,92,,,,7,
27-
System,65,4,12131,,8,8,9,,4,,33,3,1,3,10139,1992
27+
System,65,4,12142,,8,8,9,,4,,33,3,1,3,10151,1991
2828
Windows.Security.Cryptography.Core,1,,,,,,,1,,,,,,,,

csharp/documentation/library-coverage/coverage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ C# framework & library support
88

99
Framework / library,Package,Flow sources,Taint & value steps,Sinks (total),`CWE-079` :sub:`Cross-site scripting`
1010
`ServiceStack <https://servicestack.net/>`_,"``ServiceStack.*``, ``ServiceStack``",,7,194,
11-
System,"``System.*``, ``System``",4,12131,65,7
11+
System,"``System.*``, ``System``",4,12142,65,7
1212
Others,"``Dapper``, ``JsonToItemsTaskFactory``, ``Microsoft.ApplicationBlocks.Data``, ``Microsoft.CSharp``, ``Microsoft.EntityFrameworkCore``, ``Microsoft.Extensions.Caching.Distributed``, ``Microsoft.Extensions.Caching.Memory``, ``Microsoft.Extensions.Configuration``, ``Microsoft.Extensions.DependencyInjection``, ``Microsoft.Extensions.DependencyModel``, ``Microsoft.Extensions.FileProviders``, ``Microsoft.Extensions.FileSystemGlobbing``, ``Microsoft.Extensions.Hosting``, ``Microsoft.Extensions.Http``, ``Microsoft.Extensions.Logging``, ``Microsoft.Extensions.Options``, ``Microsoft.Extensions.Primitives``, ``Microsoft.Interop``, ``Microsoft.NET.Build.Tasks``, ``Microsoft.NETCore.Platforms.BuildTasks``, ``Microsoft.VisualBasic``, ``Microsoft.Win32``, ``MySql.Data.MySqlClient``, ``Newtonsoft.Json``, ``Windows.Security.Cryptography.Core``",,556,138,
13-
Totals,,4,12694,397,7
13+
Totals,,4,12705,397,7
1414

0 commit comments

Comments
 (0)