Skip to content

Commit 71c1ca5

Browse files
authored
Merge branch 'main' into rncrypt
2 parents 037b49b + 3a4623b commit 71c1ca5

File tree

194 files changed

+29571
-775
lines changed

Some content is hidden

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

194 files changed

+29571
-775
lines changed

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

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,73 @@ jobs:
3333
~/.cargo/registry
3434
~/.cargo/git
3535
ql/target
36-
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-qltest-cargo-${{ hashFiles('ql/**/Cargo.lock') }}
36+
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-qltest-cargo-${{ hashFiles('ql/rust-toolchain.toml', 'ql/**/Cargo.lock') }}
3737
- name: Build extractor
3838
run: |
3939
cd ql;
4040
codeqlpath=$(dirname ${{ steps.find-codeql.outputs.codeql-path }});
4141
env "PATH=$PATH:$codeqlpath" ./scripts/create-extractor-pack.sh
42+
- name: Cache compilation cache
43+
id: query-cache
44+
uses: ./.github/actions/cache-query-compilation
45+
with:
46+
key: ql-for-ql-tests
4247
- name: Run QL tests
4348
run: |
44-
"${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
49+
"${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 --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" ql/ql/test
4550
env:
4651
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
47-
- name: Check QL formatting
52+
53+
other-os:
54+
strategy:
55+
matrix:
56+
os: [macos-latest, windows-latest]
57+
needs: [qltest]
58+
runs-on: ${{ matrix.os }}
59+
steps:
60+
- uses: actions/checkout@v3
61+
- name: Install GNU tar
62+
if: runner.os == 'macOS'
63+
run: |
64+
brew install gnu-tar
65+
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
66+
- name: Find codeql
67+
id: find-codeql
68+
uses: github/codeql-action/init@77a8d2d10c0b403a8b4aadbd223dc489ecd22683
69+
with:
70+
languages: javascript # does not matter
71+
- uses: ./.github/actions/os-version
72+
id: os_version
73+
- uses: actions/cache@v3
74+
with:
75+
path: |
76+
~/.cargo/registry
77+
~/.cargo/git
78+
ql/target
79+
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-qltest-cargo-${{ hashFiles('ql/rust-toolchain.toml', 'ql/**/Cargo.lock') }}
80+
- name: Build extractor
81+
if: runner.os != 'Windows'
82+
run: |
83+
cd ql;
84+
codeqlpath=$(dirname ${{ steps.find-codeql.outputs.codeql-path }});
85+
env "PATH=$PATH:$codeqlpath" ./scripts/create-extractor-pack.sh
86+
- name: Build extractor (Windows)
87+
if: runner.os == 'Windows'
88+
shell: pwsh
4889
run: |
49-
find ql/ql/src "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 "${CODEQL}" query format --check-only
90+
cd ql;
91+
$Env:PATH += ";$(dirname ${{ steps.find-codeql.outputs.codeql-path }})"
92+
pwsh ./scripts/create-extractor-pack.ps1
93+
- name: Run a single QL tests - Unix
94+
if: runner.os != 'Windows'
95+
run: |
96+
"${CODEQL}" test run --check-databases --search-path "${{ github.workspace }}/ql/extractor-pack" ql/ql/test/queries/style/DeadCode/DeadCode.qlref
5097
env:
5198
CODEQL: ${{ steps.find-codeql.outputs.codeql-path }}
99+
- name: Run a single QL tests - Windows
100+
if: runner.os == 'Windows'
101+
shell: pwsh
102+
run: |
103+
$Env:PATH += ";$(dirname ${{ steps.find-codeql.outputs.codeql-path }})"
104+
codeql test run --check-databases --search-path "${{ github.workspace }}/ql/extractor-pack" ql/ql/test/queries/style/DeadCode/DeadCode.qlref
105+

.github/workflows/ruby-build.yml

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ jobs:
205205
- name: Fetch CodeQL
206206
uses: ./.github/actions/fetch-codeql
207207

208-
- uses: actions/checkout@v3
209-
with:
210-
repository: Shopify/example-ruby-app
211-
ref: 67a0decc5eb550f3a9228eda53925c3afd40dfe9
212-
213208
- name: Download Ruby bundle
214209
uses: actions/download-artifact@v3
215210
with:
@@ -218,26 +213,15 @@ jobs:
218213
- name: Unzip Ruby bundle
219214
shell: bash
220215
run: unzip -q -d "${{ runner.temp }}/ruby-bundle" "${{ runner.temp }}/codeql-ruby-bundle.zip"
221-
- name: Prepare test files
222-
shell: bash
223-
run: |
224-
echo "import codeql.ruby.AST select count(File f)" > "test.ql"
225-
echo "| 4 |" > "test.expected"
226-
echo 'name: sample-tests
227-
version: 0.0.0
228-
dependencies:
229-
codeql/ruby-all: "*"
230-
extractor: ruby
231-
tests: .
232-
' > qlpack.yml
216+
233217
- name: Run QL test
234218
shell: bash
235219
run: |
236-
codeql test run --search-path "${{ runner.temp }}/ruby-bundle" --additional-packs "${{ runner.temp }}/ruby-bundle" .
220+
codeql test run --search-path "${{ runner.temp }}/ruby-bundle" --additional-packs "${{ runner.temp }}/ruby-bundle" ruby/ql/test/library-tests/ast/constants/
237221
- name: Create database
238222
shell: bash
239223
run: |
240-
codeql database create --search-path "${{ runner.temp }}/ruby-bundle" --language ruby --source-root . ../database
224+
codeql database create --search-path "${{ runner.temp }}/ruby-bundle" --language ruby --source-root ruby/ql/test/library-tests/ast/constants/ ../database
241225
- name: Analyze database
242226
shell: bash
243227
run: |

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
@@ -45,6 +45,16 @@ module Consistency {
4545
) {
4646
none()
4747
}
48+
49+
/** Holds if `(c, pos, p)` should be excluded from the consistency test `uniqueParameterNodeAtPosition`. */
50+
predicate uniqueParameterNodeAtPositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
51+
none()
52+
}
53+
54+
/** Holds if `(c, pos, p)` should be excluded from the consistency test `uniqueParameterNodePosition`. */
55+
predicate uniqueParameterNodePositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
56+
none()
57+
}
4858
}
4959

5060
private class RelevantNode extends Node {
@@ -246,6 +256,7 @@ module Consistency {
246256
query predicate uniqueParameterNodeAtPosition(
247257
DataFlowCallable c, ParameterPosition pos, Node p, string msg
248258
) {
259+
not any(ConsistencyConfiguration conf).uniqueParameterNodeAtPositionExclude(c, pos, p) and
249260
isParameterNode(p, c, pos) and
250261
not exists(unique(Node p0 | isParameterNode(p0, c, pos))) and
251262
msg = "Parameters with overlapping positions."
@@ -254,6 +265,7 @@ module Consistency {
254265
query predicate uniqueParameterNodePosition(
255266
DataFlowCallable c, ParameterPosition pos, Node p, string msg
256267
) {
268+
not any(ConsistencyConfiguration conf).uniqueParameterNodePositionExclude(c, pos, p) and
257269
isParameterNode(p, c, pos) and
258270
not exists(unique(ParameterPosition pos0 | isParameterNode(p, c, pos0))) and
259271
msg = "Parameter node with multiple positions."

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ module Consistency {
4545
) {
4646
none()
4747
}
48+
49+
/** Holds if `(c, pos, p)` should be excluded from the consistency test `uniqueParameterNodeAtPosition`. */
50+
predicate uniqueParameterNodeAtPositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
51+
none()
52+
}
53+
54+
/** Holds if `(c, pos, p)` should be excluded from the consistency test `uniqueParameterNodePosition`. */
55+
predicate uniqueParameterNodePositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
56+
none()
57+
}
4858
}
4959

5060
private class RelevantNode extends Node {
@@ -246,6 +256,7 @@ module Consistency {
246256
query predicate uniqueParameterNodeAtPosition(
247257
DataFlowCallable c, ParameterPosition pos, Node p, string msg
248258
) {
259+
not any(ConsistencyConfiguration conf).uniqueParameterNodeAtPositionExclude(c, pos, p) and
249260
isParameterNode(p, c, pos) and
250261
not exists(unique(Node p0 | isParameterNode(p0, c, pos))) and
251262
msg = "Parameters with overlapping positions."
@@ -254,6 +265,7 @@ module Consistency {
254265
query predicate uniqueParameterNodePosition(
255266
DataFlowCallable c, ParameterPosition pos, Node p, string msg
256267
) {
268+
not any(ConsistencyConfiguration conf).uniqueParameterNodePositionExclude(c, pos, p) and
257269
isParameterNode(p, c, pos) and
258270
not exists(unique(ParameterPosition pos0 | isParameterNode(p, c, pos0))) and
259271
msg = "Parameter node with multiple positions."

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
@@ -45,6 +45,16 @@ module Consistency {
4545
) {
4646
none()
4747
}
48+
49+
/** Holds if `(c, pos, p)` should be excluded from the consistency test `uniqueParameterNodeAtPosition`. */
50+
predicate uniqueParameterNodeAtPositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
51+
none()
52+
}
53+
54+
/** Holds if `(c, pos, p)` should be excluded from the consistency test `uniqueParameterNodePosition`. */
55+
predicate uniqueParameterNodePositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
56+
none()
57+
}
4858
}
4959

5060
private class RelevantNode extends Node {
@@ -246,6 +256,7 @@ module Consistency {
246256
query predicate uniqueParameterNodeAtPosition(
247257
DataFlowCallable c, ParameterPosition pos, Node p, string msg
248258
) {
259+
not any(ConsistencyConfiguration conf).uniqueParameterNodeAtPositionExclude(c, pos, p) and
249260
isParameterNode(p, c, pos) and
250261
not exists(unique(Node p0 | isParameterNode(p0, c, pos))) and
251262
msg = "Parameters with overlapping positions."
@@ -254,6 +265,7 @@ module Consistency {
254265
query predicate uniqueParameterNodePosition(
255266
DataFlowCallable c, ParameterPosition pos, Node p, string msg
256267
) {
268+
not any(ConsistencyConfiguration conf).uniqueParameterNodePositionExclude(c, pos, p) and
257269
isParameterNode(p, c, pos) and
258270
not exists(unique(ParameterPosition pos0 | isParameterNode(p, c, pos0))) and
259271
msg = "Parameter node with multiple positions."

cpp/ql/src/Security/CWE/CWE-290/AuthenticationBypass.ql

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,76 +15,24 @@
1515
import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl
1616
import TaintedWithPath
1717

18+
string getATopLevelDomain() {
19+
result =
20+
[
21+
"com", "ru", "net", "org", "de", "jp", "uk", "br", "pl", "in", "it", "fr", "au", "info", "nl",
22+
"cn", "ir", "es", "cz", "biz", "ca", "eu", "ua", "kr", "za", "co", "gr", "ro", "se", "tw",
23+
"vn", "mx", "ch", "tr", "at", "be", "hu", "tv", "dk", "me", "ar", "us", "no", "sk", "fi",
24+
"id", "cl", "nz", "by", "xyz", "pt", "ie", "il", "kz", "my", "hk", "lt", "cc", "sg", "io",
25+
"edu", "gov"
26+
]
27+
}
28+
1829
predicate hardCodedAddressOrIP(StringLiteral txt) {
1930
exists(string s | s = txt.getValueText() |
2031
// Hard-coded ip addresses, such as 127.0.0.1
2132
s.regexpMatch("\"[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+\"") or
2233
// Hard-coded addresses such as www.mycompany.com
23-
s.matches("\"www.%\"") or
24-
s.matches("\"http:%\"") or
25-
s.matches("\"https:%\"") or
26-
s.matches("\"%.com\"") or
27-
s.matches("\"%.ru\"") or
28-
s.matches("\"%.net\"") or
29-
s.matches("\"%.org\"") or
30-
s.matches("\"%.de\"") or
31-
s.matches("\"%.jp\"") or
32-
s.matches("\"%.uk\"") or
33-
s.matches("\"%.br\"") or
34-
s.matches("\"%.pl\"") or
35-
s.matches("\"%.in\"") or
36-
s.matches("\"%.it\"") or
37-
s.matches("\"%.fr\"") or
38-
s.matches("\"%.au\"") or
39-
s.matches("\"%.info\"") or
40-
s.matches("\"%.nl\"") or
41-
s.matches("\"%.cn\"") or
42-
s.matches("\"%.ir\"") or
43-
s.matches("\"%.es\"") or
44-
s.matches("\"%.cz\"") or
45-
s.matches("\"%.biz\"") or
46-
s.matches("\"%.ca\"") or
47-
s.matches("\"%.eu\"") or
48-
s.matches("\"%.ua\"") or
49-
s.matches("\"%.kr\"") or
50-
s.matches("\"%.za\"") or
51-
s.matches("\"%.co\"") or
52-
s.matches("\"%.gr\"") or
53-
s.matches("\"%.ro\"") or
54-
s.matches("\"%.se\"") or
55-
s.matches("\"%.tw\"") or
56-
s.matches("\"%.vn\"") or
57-
s.matches("\"%.mx\"") or
58-
s.matches("\"%.ch\"") or
59-
s.matches("\"%.tr\"") or
60-
s.matches("\"%.at\"") or
61-
s.matches("\"%.be\"") or
62-
s.matches("\"%.hu\"") or
63-
s.matches("\"%.tv\"") or
64-
s.matches("\"%.dk\"") or
65-
s.matches("\"%.me\"") or
66-
s.matches("\"%.ar\"") or
67-
s.matches("\"%.us\"") or
68-
s.matches("\"%.no\"") or
69-
s.matches("\"%.sk\"") or
70-
s.matches("\"%.fi\"") or
71-
s.matches("\"%.id\"") or
72-
s.matches("\"%.cl\"") or
73-
s.matches("\"%.nz\"") or
74-
s.matches("\"%.by\"") or
75-
s.matches("\"%.xyz\"") or
76-
s.matches("\"%.pt\"") or
77-
s.matches("\"%.ie\"") or
78-
s.matches("\"%.il\"") or
79-
s.matches("\"%.kz\"") or
80-
s.matches("\"%.my\"") or
81-
s.matches("\"%.hk\"") or
82-
s.matches("\"%.lt\"") or
83-
s.matches("\"%.cc\"") or
84-
s.matches("\"%.sg\"") or
85-
s.matches("\"%.io\"") or
86-
s.matches("\"%.edu\"") or
87-
s.matches("\"%.gov\"")
34+
s.regexpMatch("\"(www\\.|http:|https:).*\"") or
35+
s.regexpMatch("\".*\\.(" + strictconcat(getATopLevelDomain(), "|") + ")\"")
8836
)
8937
}
9038

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -207,34 +207,35 @@ bad_asts.cpp:
207207
# 27| Type = [SpecifiedType] const Point
208208
# 27| ValueCategory = lvalue
209209
# 28| getStmt(1): [ReturnStmt] return ...
210-
# 30| [TopLevelFunction] void Bad::errorExpr()
211-
# 30| <params>:
212-
# 30| getEntryPoint(): [BlockStmt] { ... }
213-
# 31| getStmt(0): [DeclStmt] declaration
214-
# 31| getDeclarationEntry(0): [VariableDeclarationEntry] definition of intref
215-
# 31| Type = [LValueReferenceType] int &
216-
# 31| getVariable().getInitializer(): [Initializer] initializer for intref
217-
# 31| getExpr(): [ErrorExpr] <error expr>
218-
# 31| Type = [ErroneousType] error
219-
# 31| ValueCategory = prvalue
220-
# 32| getStmt(1): [DeclStmt] declaration
221-
# 32| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
222-
# 32| Type = [IntType] int
223-
# 32| getVariable().getInitializer(): [Initializer] initializer for x
224-
# 32| getExpr(): [ErrorExpr] <error expr>
225-
# 32| Type = [ErroneousType] error
226-
# 32| ValueCategory = prvalue
227-
# 33| getStmt(2): [ExprStmt] ExprStmt
228-
# 33| getExpr(): [AssignExpr] ... = ...
229-
# 33| Type = [IntType] int
230-
# 33| ValueCategory = lvalue
231-
# 33| getLValue(): [VariableAccess] x
232-
# 33| Type = [IntType] int
233-
# 33| ValueCategory = lvalue
234-
# 33| getRValue(): [ErrorExpr] <error expr>
235-
# 33| Type = [ErroneousType] error
236-
# 33| ValueCategory = prvalue(load)
237-
# 34| getStmt(3): [ReturnStmt] return ...
210+
bad_stmts.cpp:
211+
# 5| [TopLevelFunction] void Bad::errorExpr()
212+
# 5| <params>:
213+
# 5| getEntryPoint(): [BlockStmt] { ... }
214+
# 6| getStmt(0): [DeclStmt] declaration
215+
# 6| getDeclarationEntry(0): [VariableDeclarationEntry] definition of intref
216+
# 6| Type = [LValueReferenceType] int &
217+
# 6| getVariable().getInitializer(): [Initializer] initializer for intref
218+
# 6| getExpr(): [ErrorExpr] <error expr>
219+
# 6| Type = [ErroneousType] error
220+
# 6| ValueCategory = prvalue
221+
# 7| getStmt(1): [DeclStmt] declaration
222+
# 7| getDeclarationEntry(0): [VariableDeclarationEntry] definition of x
223+
# 7| Type = [IntType] int
224+
# 7| getVariable().getInitializer(): [Initializer] initializer for x
225+
# 7| getExpr(): [ErrorExpr] <error expr>
226+
# 7| Type = [ErroneousType] error
227+
# 7| ValueCategory = prvalue
228+
# 8| getStmt(2): [ExprStmt] ExprStmt
229+
# 8| getExpr(): [AssignExpr] ... = ...
230+
# 8| Type = [IntType] int
231+
# 8| ValueCategory = lvalue
232+
# 8| getLValue(): [VariableAccess] x
233+
# 8| Type = [IntType] int
234+
# 8| ValueCategory = lvalue
235+
# 8| getRValue(): [ErrorExpr] <error expr>
236+
# 8| Type = [ErroneousType] error
237+
# 8| ValueCategory = prvalue(load)
238+
# 9| getStmt(3): [ReturnStmt] return ...
238239
clang.cpp:
239240
# 5| [TopLevelFunction] int* globalIntAddress()
240241
# 5| <params>:

cpp/ql/test/library-tests/ir/ir/bad_asts.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// semmle-extractor-options: -std=c++17 --expect_errors
1+
// semmle-extractor-options: -std=c++17
22

33
// Test cases that illustrate known bad ASTs that we have to work around in IR generation.
44
namespace Bad {
@@ -26,10 +26,4 @@ namespace Bad {
2626
void CallCopyConstructor(const Point& a) {
2727
Point b = a; // Copy constructor contains literal expressions with no values.
2828
}
29-
30-
void errorExpr() {
31-
int &intref = 0;
32-
int x = 0[0];
33-
x = 1[1];
34-
}
3529
}

0 commit comments

Comments
 (0)