Skip to content

Commit ae6b7b0

Browse files
committed
Merge branch 'main' into sql1
2 parents 49e0028 + edb9b47 commit ae6b7b0

File tree

567 files changed

+16685
-4456
lines changed

Some content is hidden

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

567 files changed

+16685
-4456
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup dotnet
3131
uses: actions/setup-dotnet@v4
3232
with:
33-
dotnet-version: 8.0.101
33+
dotnet-version: 9.0.100
3434

3535
- name: Checkout repository
3636
uses: actions/checkout@v4

.github/workflows/cpp-swift-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: "Build Swift extractor using Bazel"
4949
run: |
5050
bazel clean --expunge
51-
bazel run //swift:create-extractor-pack --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --spawn_strategy=local
51+
bazel run //swift:install --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --spawn_strategy=local
5252
bazel shutdown
5353
5454
- name: Perform CodeQL Analysis

.github/workflows/csharp-qltest.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ jobs:
3939
- name: Setup dotnet
4040
uses: actions/setup-dotnet@v4
4141
with:
42-
dotnet-version: 8.0.101
42+
dotnet-version: 9.0.100
4343
- name: Extractor unit tests
4444
run: |
4545
dotnet tool restore
46-
dotnet test -p:RuntimeFrameworkVersion=8.0.1 extractor/Semmle.Util.Tests
47-
dotnet test -p:RuntimeFrameworkVersion=8.0.1 extractor/Semmle.Extraction.Tests
48-
dotnet test -p:RuntimeFrameworkVersion=8.0.1 autobuilder/Semmle.Autobuild.CSharp.Tests
49-
dotnet test -p:RuntimeFrameworkVersion=8.0.1 autobuilder/Semmle.Autobuild.Cpp.Tests
46+
dotnet test -p:RuntimeFrameworkVersion=9.0.0 extractor/Semmle.Util.Tests
47+
dotnet test -p:RuntimeFrameworkVersion=9.0.0 extractor/Semmle.Extraction.Tests
48+
dotnet test -p:RuntimeFrameworkVersion=9.0.0 autobuilder/Semmle.Autobuild.CSharp.Tests
49+
dotnet test -p:RuntimeFrameworkVersion=9.0.0 autobuilder/Semmle.Autobuild.Cpp.Tests
5050
shell: bash
5151
stubgentest:
5252
runs-on: ubuntu-latest

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
2525
bazel_dep(name = "fmt", version = "10.0.0")
2626
bazel_dep(name = "rules_kotlin", version = "2.0.0-codeql.1")
2727
bazel_dep(name = "gazelle", version = "0.38.0")
28-
bazel_dep(name = "rules_dotnet", version = "0.16.1")
28+
bazel_dep(name = "rules_dotnet", version = "0.17.4")
2929
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
3030
bazel_dep(name = "rules_rust", version = "0.52.2")
3131

@@ -71,7 +71,7 @@ tree_sitter_extractors_deps = use_extension("//misc/bazel/3rdparty:tree_sitter_e
7171
use_repo(tree_sitter_extractors_deps, "vendor__anyhow-1.0.93", "vendor__argfile-0.2.1", "vendor__chrono-0.4.38", "vendor__clap-4.5.20", "vendor__encoding-0.2.33", "vendor__figment-0.10.19", "vendor__flate2-1.0.34", "vendor__glob-0.3.1", "vendor__globset-0.4.15", "vendor__itertools-0.10.5", "vendor__itertools-0.13.0", "vendor__lazy_static-1.5.0", "vendor__log-0.4.22", "vendor__num-traits-0.2.19", "vendor__num_cpus-1.16.0", "vendor__proc-macro2-1.0.89", "vendor__quote-1.0.37", "vendor__ra_ap_base_db-0.0.232", "vendor__ra_ap_cfg-0.0.232", "vendor__ra_ap_hir-0.0.232", "vendor__ra_ap_hir_def-0.0.232", "vendor__ra_ap_hir_expand-0.0.232", "vendor__ra_ap_ide_db-0.0.232", "vendor__ra_ap_intern-0.0.232", "vendor__ra_ap_load-cargo-0.0.232", "vendor__ra_ap_parser-0.0.232", "vendor__ra_ap_paths-0.0.232", "vendor__ra_ap_project_model-0.0.232", "vendor__ra_ap_span-0.0.232", "vendor__ra_ap_syntax-0.0.232", "vendor__ra_ap_vfs-0.0.232", "vendor__rand-0.8.5", "vendor__rayon-1.10.0", "vendor__regex-1.11.1", "vendor__serde-1.0.214", "vendor__serde_json-1.0.132", "vendor__serde_with-3.11.0", "vendor__stderrlog-0.6.0", "vendor__syn-2.0.87", "vendor__tracing-0.1.40", "vendor__tracing-subscriber-0.3.18", "vendor__tree-sitter-0.24.4", "vendor__tree-sitter-embedded-template-0.23.2", "vendor__tree-sitter-json-0.24.8", "vendor__tree-sitter-ql-0.23.1", "vendor__tree-sitter-ruby-0.23.1", "vendor__triomphe-0.1.14", "vendor__ungrammar-1.16.1")
7272

7373
dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
74-
dotnet.toolchain(dotnet_version = "8.0.101")
74+
dotnet.toolchain(dotnet_version = "9.0.100")
7575
use_repo(dotnet, "dotnet_toolchains")
7676

7777
register_toolchains("@dotnet_toolchains//:all")

actions/BUILD.bazel

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@ load("//misc/bazel:pkg.bzl", "codeql_pack")
22

33
package(default_visibility = ["//visibility:public"])
44

5-
[
6-
codeql_pack(
7-
name = "-".join(parts),
8-
srcs = [
9-
"//actions/extractor",
10-
],
11-
pack_prefix = "/".join(parts),
12-
)
13-
for parts in (
14-
[
15-
"experimental",
16-
"actions",
17-
],
18-
["actions"],
19-
)
20-
]
5+
codeql_pack(
6+
name = "actions",
7+
srcs = ["//actions/extractor"],
8+
experimental = True,
9+
)

cpp/ql/src/Critical/UseAfterFree.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<p>
99
This rule finds accesses through a pointer of a memory location that has already been freed (i.e. through a dangling pointer).
1010
Such memory blocks have already been released to the dynamic memory manager, and modifying them can lead to anything
11-
from a segfault to memory corruption that would cause subsequent calls to the dynamic memory manger to behave
11+
from a segfault to memory corruption that would cause subsequent calls to the dynamic memory manager to behave
1212
erratically, to a possible security vulnerability.
1313
</p>
1414

cpp/ql/src/experimental/Best Practices/GuardedFree.ql

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,31 @@ class FreeCall extends FunctionCall {
1818
FreeCall() { this.getTarget().hasGlobalName("free") }
1919
}
2020

21+
predicate blockContainsPreprocessorBranches(BasicBlock bb) {
22+
exists(PreprocessorBranch ppb, Location bbLoc, Location ppbLoc |
23+
bbLoc = bb.(Stmt).getLocation() and ppbLoc = ppb.getLocation()
24+
|
25+
bbLoc.getFile() = ppb.getFile() and
26+
bbLoc.getStartLine() < ppbLoc.getStartLine() and
27+
ppbLoc.getEndLine() < bbLoc.getEndLine()
28+
)
29+
}
30+
2131
from GuardCondition gc, FreeCall fc, Variable v, BasicBlock bb
2232
where
2333
gc.ensuresEq(v.getAnAccess(), 0, bb, false) and
2434
fc.getArgument(0) = v.getAnAccess() and
25-
bb = fc.getEnclosingStmt()
35+
bb = fc.getBasicBlock() and
36+
(
37+
// No block statement: if (x) free(x);
38+
bb = fc.getEnclosingStmt()
39+
or
40+
// Block statement with a single nested statement: if (x) { free(x); }
41+
strictcount(bb.(BlockStmt).getAStmt()) = 1
42+
) and
43+
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1 and
44+
not fc.isInMacroExpansion() and
45+
not blockContainsPreprocessorBranches(bb) and
46+
not (gc instanceof BinaryOperation and not gc instanceof ComparisonOperation) and
47+
not exists(CommaExpr c | c.getAChild*() = fc)
2648
select gc, "unnecessary NULL check before call to $@", fc, "free"
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
| test.cpp:5:7:5:7 | x | unnecessary NULL check before call to $@ | test.cpp:6:5:6:8 | call to free | free |
2-
| test.cpp:23:7:23:7 | x | unnecessary NULL check before call to $@ | test.cpp:26:5:26:8 | call to free | free |
3-
| test.cpp:31:7:31:8 | ! ... | unnecessary NULL check before call to $@ | test.cpp:35:3:35:6 | call to free | free |
4-
| test.cpp:31:7:31:24 | ... \|\| ... | unnecessary NULL check before call to $@ | test.cpp:35:3:35:6 | call to free | free |
5-
| test.cpp:31:8:31:8 | x | unnecessary NULL check before call to $@ | test.cpp:35:3:35:6 | call to free | free |
6-
| test.cpp:94:12:94:12 | x | unnecessary NULL check before call to $@ | test.cpp:94:3:94:13 | call to free | free |
7-
| test.cpp:98:7:98:8 | ! ... | unnecessary NULL check before call to $@ | test.cpp:101:3:101:6 | call to free | free |
8-
| test.cpp:98:8:98:8 | x | unnecessary NULL check before call to $@ | test.cpp:101:3:101:6 | call to free | free |
2+
| test.cpp:10:7:10:7 | x | unnecessary NULL check before call to $@ | test.cpp:11:5:11:8 | call to free | free |
3+
| test.cpp:42:7:42:7 | x | unnecessary NULL check before call to $@ | test.cpp:43:5:43:8 | call to free | free |
4+
| test.cpp:49:7:49:7 | x | unnecessary NULL check before call to $@ | test.cpp:50:5:50:8 | call to free | free |
95
| test.cpp:106:7:106:18 | ... != ... | unnecessary NULL check before call to $@ | test.cpp:107:5:107:8 | call to free | free |
10-
| test.cpp:113:7:113:18 | ... != ... | unnecessary NULL check before call to $@ | test.cpp:114:17:114:20 | call to free | free |

cpp/ql/test/experimental/query-tests/Best Practices/GuardedFree/test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ void test2(int *x) {
2020
}
2121

2222
void test3(int *x, bool b) {
23-
if (x) { // GOOD [FALSE POSITIVE]: x is being accessed in the body of the if
23+
if (x) { // GOOD: x is being accessed in the body of the if
2424
if (b)
2525
*x = 42;
2626
free(x);
2727
}
2828
}
2929

3030
bool test4(char *x, char *y) {
31-
if (!x || strcmp(x, y)) { // GOOD [FALSE POSITIVE]: x is being accessed in the guard and return value depends on x
31+
if (!x || strcmp(x, y)) { // GOOD: x is being accessed in the guard and return value depends on x
3232
free(x);
3333
return true;
3434
}
@@ -91,11 +91,11 @@ void test10(char *x) {
9191
if (x) free(x);
9292

9393
void test11(char *x) {
94-
TRY_FREE(x) // BAD
94+
TRY_FREE(x) // BAD [NOT DETECTED]
9595
}
9696

9797
bool test12(char *x) {
98-
if (!x) // GOOD [FALSE POSITIVE]: return value depends on x
98+
if (!x) // GOOD: return value depends on x
9999
return false;
100100

101101
free(x);
@@ -110,6 +110,6 @@ void test13(char *x) {
110110
void inspect(char *x);
111111

112112
void test14(char *x) {
113-
if (x != nullptr) // GOOD [FALSE POSITIVE]: x might be accessed in the first operand of the comma operator
113+
if (x != nullptr) // GOOD: x might be accessed in the first operand of the comma operator
114114
inspect(x), free(x);
115115
}

csharp/.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"paket": {
6-
"version": "8.0.3",
6+
"version": "9.0.1",
77
"commands": [
88
"paket"
99
]

0 commit comments

Comments
 (0)