Skip to content

Commit 98fc881

Browse files
committed
Merge 'main' into redsun82/swift-extraction
2 parents c779936 + cc5f59f commit 98fc881

File tree

182 files changed

+6961
-2682
lines changed

Some content is hidden

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

182 files changed

+6961
-2682
lines changed

.github/workflows/ql-for-ql-build.yml

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ env:
1010
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
queries:
14-
runs-on: ubuntu-latest
13+
analyze:
14+
runs-on: ubuntu-latest-xl
1515
steps:
16+
### Build the queries ###
1617
- uses: actions/checkout@v3
1718
- name: Find codeql
1819
id: find-codeql
1920
uses: github/codeql-action/init@aa93aea877e5fb8841bcb1193f672abf6e9f2980
2021
with:
2122
languages: javascript # does not matter
22-
tools: latest
2323
- name: Get CodeQL version
2424
id: get-codeql-version
2525
run: |
@@ -49,14 +49,7 @@ jobs:
4949
name: query-pack-zip
5050
path: ${{ runner.temp }}/query-pack.zip
5151

52-
extractors:
53-
strategy:
54-
fail-fast: false
55-
56-
runs-on: ubuntu-latest
57-
58-
steps:
59-
- uses: actions/checkout@v3
52+
### Build the extractor ###
6053
- name: Cache entire extractor
6154
id: cache-extractor
6255
uses: actions/cache@v3
@@ -100,15 +93,8 @@ jobs:
10093
ql/target/release/ql-extractor
10194
ql/target/release/ql-extractor.exe
10295
retention-days: 1
103-
package:
104-
runs-on: ubuntu-latest
105-
106-
needs:
107-
- extractors
108-
- queries
10996

110-
steps:
111-
- uses: actions/checkout@v3
97+
### Package the queries and extractor ###
11298
- uses: actions/download-artifact@v3
11399
with:
114100
name: query-pack-zip
@@ -136,16 +122,8 @@ jobs:
136122
name: codeql-ql-pack
137123
path: codeql-ql.zip
138124
retention-days: 1
139-
analyze:
140-
runs-on: ubuntu-latest
141-
strategy:
142-
matrix:
143-
folder: [cpp, csharp, java, javascript, python, ql, ruby, swift, go]
144-
145-
needs:
146-
- package
147125

148-
steps:
126+
### Run the analysis ###
149127
- name: Download pack
150128
uses: actions/download-artifact@v3
151129
with:
@@ -165,39 +143,46 @@ jobs:
165143
env:
166144
PACK: ${{ runner.temp }}/pack
167145

168-
- name: Checkout repository
169-
uses: actions/checkout@v3
170146
- name: Create CodeQL config file
171147
run: |
172-
echo "paths:" > ${CONF}
173-
echo " - ${FOLDER}" >> ${CONF}
174148
echo "paths-ignore:" >> ${CONF}
175149
echo " - ql/ql/test" >> ${CONF}
150+
echo " - \"*/ql/lib/upgrades/\"" >> ${CONF}
176151
echo "disable-default-queries: true" >> ${CONF}
177152
echo "packs:" >> ${CONF}
178153
echo " - codeql/ql" >> ${CONF}
179154
echo "Config file: "
180155
cat ${CONF}
181156
env:
182157
CONF: ./ql-for-ql-config.yml
183-
FOLDER: ${{ matrix.folder }}
184158
- name: Initialize CodeQL
185159
uses: github/codeql-action/init@aa93aea877e5fb8841bcb1193f672abf6e9f2980
186160
with:
187161
languages: ql
188162
db-location: ${{ runner.temp }}/db
189163
config-file: ./ql-for-ql-config.yml
190-
tools: latest
191164

192165
- name: Perform CodeQL Analysis
193166
uses: github/codeql-action/analyze@aa93aea877e5fb8841bcb1193f672abf6e9f2980
194167
with:
195-
category: "ql-for-ql-${{ matrix.folder }}"
168+
category: "ql-for-ql"
196169
- name: Copy sarif file to CWD
197-
run: cp ../results/ql.sarif ./${{ matrix.folder }}.sarif
170+
run: cp ../results/ql.sarif ./ql-for-ql.sarif
171+
- name: Fixup the $scema in sarif # Until https://github.com/microsoft/sarif-vscode-extension/pull/436/ is part in a stable release
172+
run: |
173+
sed -i 's/\$schema.*/\$schema": "https:\/\/raw.githubusercontent.com\/oasis-tcs\/sarif-spec\/master\/Schemata\/sarif-schema-2.1.0",/' ql-for-ql.sarif
198174
- name: Sarif as artifact
199175
uses: actions/upload-artifact@v3
200176
with:
201-
name: ${{ matrix.folder }}.sarif
202-
path: ${{ matrix.folder }}.sarif
203-
177+
name: ql-for-ql.sarif
178+
path: ql-for-ql.sarif
179+
- name: Split out the sarif file into langs
180+
run: |
181+
mkdir split-sarif
182+
node ./ql/scripts/split-sarif.js ql-for-ql.sarif split-sarif
183+
- name: Upload langs as artifacts
184+
uses: actions/upload-artifact@v3
185+
with:
186+
name: ql-for-ql-langs
187+
path: split-sarif
188+
retention-days: 1

.github/workflows/ql-for-ql-dataset_measure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
ql/target
3737
key: ${{ runner.os }}-qltest-cargo-${{ hashFiles('ql/**/Cargo.lock') }}
3838
- name: Build Extractor
39-
run: cd ql; env "PATH=$PATH:`dirname ${CODEQL}`" ./create-extractor-pack.sh
39+
run: cd ql; env "PATH=$PATH:`dirname ${CODEQL}`" ./scripts/create-extractor-pack.sh
4040
env:
4141
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
4242
- name: Checkout ${{ matrix.repo }}

.github/workflows/ql-for-ql-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: |
3737
cd ql;
3838
codeqlpath=$(dirname ${{ steps.find-codeql.outputs.codeql-path }});
39-
env "PATH=$PATH:$codeqlpath" ./create-extractor-pack.sh
39+
env "PATH=$PATH:$codeqlpath" ./scripts/create-extractor-pack.sh
4040
- name: Run QL tests
4141
run: |
4242
"${CODEQL}" test run --check-databases --check-unused-labels --check-repeated-labels --check-redefined-labels --check-use-before-definition --search-path "${{ github.workspace }}/ql/extractor-pack" --consistency-queries ql/ql/consistency-queries ql/ql/test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* `AnalysedExpr::isNullCheck` and `AnalysedExpr::isValidCheck` have been updated to handle variable accesses on the left-hand side of the the C++ logical and variable declarations in conditions.

cpp/ql/lib/semmle/code/cpp/controlflow/Nullness.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ predicate nullCheckExpr(Expr checkExpr, Variable var) {
4646
or
4747
exists(LogicalAndExpr op, AnalysedExpr child |
4848
expr = op and
49-
op.getRightOperand() = child and
49+
op.getAnOperand() = child and
5050
nullCheckExpr(child, v)
5151
)
5252
or
@@ -99,7 +99,7 @@ predicate validCheckExpr(Expr checkExpr, Variable var) {
9999
or
100100
exists(LogicalAndExpr op, AnalysedExpr child |
101101
expr = op and
102-
op.getRightOperand() = child and
102+
op.getAnOperand() = child and
103103
validCheckExpr(child, v)
104104
)
105105
or
@@ -169,7 +169,10 @@ class AnalysedExpr extends Expr {
169169
*/
170170
predicate isDef(LocalScopeVariable v) {
171171
this.inCondition() and
172-
this.(Assignment).getLValue() = v.getAnAccess()
172+
(
173+
this.(Assignment).getLValue() = v.getAnAccess() or
174+
this.(ConditionDeclExpr).getVariableAccess() = v.getAnAccess()
175+
)
173176
}
174177

175178
/**

cpp/ql/lib/semmle/code/cpp/exprs/Call.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ class FunctionCall extends Call, @funbindexpr {
255255
/**
256256
* Gets the function called by this call.
257257
*
258-
* In the case of virtual function calls, the result is the most-specific function in the override tree (as
259-
* determined by the compiler) such that the target at runtime will be one of `result.getAnOverridingFunction*()`.
258+
* In the case of virtual function calls, the result is the most-specific function in the override tree
259+
* such that the target at runtime will be one of `result.getAnOverridingFunction*()`. The most-specific
260+
* function is determined by the compiler based on the compile time type of the object the function is a
261+
* member of.
260262
*/
261263
override Function getTarget() { funbind(underlyingElement(this), unresolveElement(result)) }
262264

cpp/ql/test/library-tests/controlflow/nullness/nullness.expected

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
| test.cpp:15:8:15:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is not null | is valid |
88
| test.cpp:16:8:16:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is null | is not valid |
99
| test.cpp:17:9:17:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is valid |
10-
| test.cpp:18:9:18:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
10+
| test.cpp:18:9:18:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is valid |
1111
| test.cpp:19:9:19:18 | ... && ... | test.cpp:5:13:5:13 | v | is null | is not valid |
12-
| test.cpp:20:9:20:18 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
12+
| test.cpp:20:9:20:18 | ... && ... | test.cpp:5:13:5:13 | v | is null | is not valid |
1313
| test.cpp:21:9:21:14 | ... = ... | test.cpp:5:13:5:13 | v | is null | is not valid |
1414
| test.cpp:21:9:21:14 | ... = ... | test.cpp:7:10:7:10 | b | is not null | is valid |
15-
| test.cpp:22:17:22:17 | b | test.cpp:7:10:7:10 | b | is not null | is valid |
15+
| test.cpp:22:9:22:14 | ... = ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
16+
| test.cpp:22:9:22:14 | ... = ... | test.cpp:7:13:7:13 | c | is not null | is not valid |
17+
| test.cpp:22:17:22:17 | c | test.cpp:7:13:7:13 | c | is not null | is valid |
18+
| test.cpp:23:21:23:21 | x | test.cpp:23:14:23:14 | x | is not null | is valid |
19+
| test.cpp:24:9:24:18 | (condition decl) | test.cpp:5:13:5:13 | v | is not null | is not valid |
20+
| test.cpp:24:9:24:18 | (condition decl) | test.cpp:24:14:24:14 | y | is not null | is valid |

cpp/ql/test/library-tests/controlflow/nullness/nullness.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import cpp
22

33
from AnalysedExpr a, LocalScopeVariable v, string isNullCheck, string isValidCheck
44
where
5-
a.getParent() instanceof IfStmt and
65
v.getAnAccess().getEnclosingStmt() = a.getParent() and
76
(if a.isNullCheck(v) then isNullCheck = "is null" else isNullCheck = "is not null") and
87
(if a.isValidCheck(v) then isValidCheck = "is valid" else isValidCheck = "is not valid")

cpp/ql/test/library-tests/controlflow/nullness/test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ long __builtin_expect(long);
44

55
void f(int *v) {
66
int *w;
7-
bool b;
7+
bool b, c;
88

99
if (v) {}
1010
if (!v) {}
@@ -19,5 +19,7 @@ void f(int *v) {
1919
if (true && !v) {}
2020
if (!v && true) {}
2121
if (b = !v) {}
22-
if (b = !v; b) {}
22+
if (c = !v; c) {}
23+
if (int *x = v; x) {}
24+
if (int *y = v) {}
2325
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
{
3+
SymmetricKey aesKey = new SymmetricKey(kid: "symencryptionkey");
4+
5+
// BAD: Using the outdated client side encryption version V1_0
6+
BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(key: aesKey, keyResolver: null);
7+
BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy };
8+
9+
MemoryStream stream = new MemoryStream(buffer);
10+
blob.UploadFromStream(stream, length: size, accessCondition: null, options: uploadOptions);
11+
}
12+
13+
var client = new BlobClient(myConnectionString, new SpecializedBlobClientOptions()
14+
{
15+
// BAD: Using an outdated SDK that does not support client side encryption version V2_0
16+
ClientSideEncryption = new ClientSideEncryptionOptions()
17+
{
18+
KeyEncryptionKey = myKey,
19+
KeyResolver = myKeyResolver,
20+
KeyWrapAlgorihm = myKeyWrapAlgorithm
21+
}
22+
});
23+
24+
var client = new BlobClient(myConnectionString, new SpecializedBlobClientOptions()
25+
{
26+
// BAD: Using the outdated client side encryption version V1_0
27+
ClientSideEncryption = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V1_0)
28+
{
29+
KeyEncryptionKey = myKey,
30+
KeyResolver = myKeyResolver,
31+
KeyWrapAlgorihm = myKeyWrapAlgorithm
32+
}
33+
});
34+
35+
var client = new BlobClient(myConnectionString, new SpecializedBlobClientOptions()
36+
{
37+
// GOOD: Using client side encryption version V2_0
38+
ClientSideEncryption = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V2_0)
39+
{
40+
KeyEncryptionKey = myKey,
41+
KeyResolver = myKeyResolver,
42+
KeyWrapAlgorihm = myKeyWrapAlgorithm
43+
}
44+
});

0 commit comments

Comments
 (0)