Skip to content

Commit 49ffa8b

Browse files
committed
Merge branch 'main' of https://github.com/github/codeql into python/test-constructor-MaD-path
2 parents 862942f + 027e5e7 commit 49ffa8b

File tree

630 files changed

+16636
-13528
lines changed

Some content is hidden

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

630 files changed

+16636
-13528
lines changed

.bazelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ build:linux --cxxopt=-std=c++20
1414
build:macos --cxxopt=-std=c++20 --cpu=darwin_x86_64
1515
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor
1616

17+
# this requires developer mode, but is required to have pack installer functioning
18+
startup --windows_enable_symlinks
19+
common --enable_runfiles
20+
21+
common --registry=file:///%workspace%/misc/bazel/registry
22+
common --registry=https://bcr.bazel.build
23+
1724
try-import %workspace%/local.bazelrc

.bazelrc.internal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this file should contain bazel settings required to build things from `semmle-code`
2+
3+
common --registry=file:///%workspace%/ql/misc/bazel/registry
4+
common --registry=https://bcr.bazel.build

.github/workflows/buildifier.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
extra_args: >
2525
buildifier --all-files 2>&1 ||
2626
(
27-
echo -e "In order to format all bazel files, please run:\n bazel run //:buildifier"; exit 1
27+
echo -e "In order to format all bazel files, please run:\n bazel run //misc/bazel:buildifier"; exit 1
2828
)

.github/workflows/go-tests-other-os.yml

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77
- .github/workflows/go-tests-other-os.yml
88
- .github/actions/**
99
- codeql-workspace.yml
10-
env:
11-
GO_VERSION: '~1.22.0'
1210

1311
permissions:
1412
contents: read
@@ -18,72 +16,17 @@ jobs:
1816
name: Test MacOS
1917
runs-on: macos-latest
2018
steps:
21-
- name: Set up Go ${{ env.GO_VERSION }}
22-
uses: actions/setup-go@v5
23-
with:
24-
go-version: ${{ env.GO_VERSION }}
25-
cache: false
26-
id: go
27-
2819
- name: Check out code
2920
uses: actions/checkout@v4
30-
31-
- name: Set up CodeQL CLI
32-
uses: ./.github/actions/fetch-codeql
33-
34-
- name: Enable problem matchers in repository
35-
shell: bash
36-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
37-
38-
- name: Build
39-
run: |
40-
cd go
41-
make
42-
43-
- name: Cache compilation cache
44-
id: query-cache
45-
uses: ./.github/actions/cache-query-compilation
46-
with:
47-
key: go-qltest
48-
- name: Test
49-
run: |
50-
cd go
51-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
21+
- name: Run tests
22+
uses: ./go/actions/test
5223

5324
test-win:
5425
if: github.repository_owner == 'github'
5526
name: Test Windows
5627
runs-on: windows-latest-xl
5728
steps:
58-
- name: Set up Go ${{ env.GO_VERSION }}
59-
uses: actions/setup-go@v5
60-
with:
61-
go-version: ${{ env.GO_VERSION }}
62-
cache: false
63-
id: go
64-
6529
- name: Check out code
6630
uses: actions/checkout@v4
67-
68-
- name: Set up CodeQL CLI
69-
uses: ./.github/actions/fetch-codeql
70-
71-
- name: Enable problem matchers in repository
72-
shell: bash
73-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
74-
75-
- name: Build
76-
run: |
77-
cd go
78-
make
79-
80-
- name: Cache compilation cache
81-
id: query-cache
82-
uses: ./.github/actions/cache-query-compilation
83-
with:
84-
key: go-qltest
85-
86-
- name: Test
87-
run: |
88-
cd go
89-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
31+
- name: Run tests
32+
uses: ./go/actions/test

.github/workflows/go-tests.yml

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ on:
1616
- .github/actions/**
1717
- codeql-workspace.yml
1818

19-
env:
20-
GO_VERSION: '~1.22.0'
21-
2219
permissions:
2320
contents: read
2421

@@ -28,51 +25,9 @@ jobs:
2825
name: Test Linux (Ubuntu)
2926
runs-on: ubuntu-latest-xl
3027
steps:
31-
- name: Set up Go ${{ env.GO_VERSION }}
32-
uses: actions/setup-go@v5
33-
with:
34-
go-version: ${{ env.GO_VERSION }}
35-
cache: false
36-
id: go
37-
3828
- name: Check out code
3929
uses: actions/checkout@v4
40-
41-
- name: Set up CodeQL CLI
42-
uses: ./.github/actions/fetch-codeql
43-
44-
- name: Enable problem matchers in repository
45-
shell: bash
46-
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'
47-
48-
- name: Build
49-
run: |
50-
cd go
51-
make
52-
53-
- name: Check that all Go code is autoformatted
54-
run: |
55-
cd go
56-
make check-formatting
57-
58-
- name: Compile qhelp files to markdown
59-
run: |
60-
cd go
61-
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown
62-
63-
- name: Upload qhelp markdown
64-
uses: actions/upload-artifact@v3
30+
- name: Run tests
31+
uses: ./go/actions/test
6532
with:
66-
name: qhelp-markdown
67-
path: go/qhelp-out/**/*.md
68-
69-
- name: Cache compilation cache
70-
id: query-cache
71-
uses: ./.github/actions/cache-query-compilation
72-
with:
73-
key: go-qltest
74-
75-
- name: Test
76-
run: |
77-
cd go
78-
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
33+
run-code-checks: true

.lfsconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[lfs]
2+
# codeql is publicly forked by many users, and we don't want any LFS file polluting their working
3+
# copies. We therefore exclude everything by default.
4+
# For files required by bazel builds, use rules in `misc/bazel/lfs.bzl` to download them on demand.
5+
fetchinclude = /nothing

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ repos:
2626
name: Format bazel files
2727
files: \.(bazel|bzl)
2828
language: system
29-
entry: bazel run //:buildifier
29+
entry: bazel run //misc/bazel:buildifier
3030
pass_filenames: false
3131

32+
# DISABLED: can be enabled by copying this config and installing `pre-commit` with `--config` on the copy
33+
# - id: go-gen
34+
# name: Check checked in generated files in go
35+
# files: ^go/.*
36+
# language: system
37+
# entry: bazel run //go:gen
38+
# pass_filenames: false
39+
3240
- id: codeql-format
3341
name: Fix QL file formatting
3442
files: \.qll?$

BUILD.bazel

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
2-
3-
buildifier(
4-
name = "buildifier",
5-
exclude_patterns = [
6-
"./.git/*",
7-
],
8-
lint_mode = "fix",
9-
)

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ We welcome contributions to our CodeQL libraries and queries. Got an idea for a
44

55
There is lots of useful documentation to help you write queries, ranging from information about query file structure to tutorials for specific target languages. For more information on the documentation available, see [CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/codeql-queries) on [codeql.github.com](https://codeql.github.com).
66

7+
Note that the CodeQL for Visual Studio Code documentation has been migrated to https://docs.github.com/en/code-security/codeql-for-vs-code/, but you can still contribute to it via a different repository. For more information, see [Contributing to GitHub Docs documentation](https://docs.github.com/en/contributing)."
8+
79
## Change notes
810

911
Any nontrivial user-visible change to a query pack or library pack should have a change note. For details on how to add a change note for your change, see [this guide](docs/change-notes.md).
@@ -43,7 +45,7 @@ If you have an idea for a query that you would like to share with other CodeQL u
4345

4446
3. **Formatting**
4547

46-
- The queries and libraries must be autoformatted, for example using the "Format Document" command in [CodeQL for Visual Studio Code](https://codeql.github.com/docs/codeql-for-visual-studio-code/about-codeql-for-visual-studio-code).
48+
- The queries and libraries must be autoformatted, for example using the "Format Document" command in [CodeQL for Visual Studio Code](https://docs.github.com/en/code-security/codeql-for-vs-code/).
4749

4850
If you prefer, you can either:
4951
1. install the [pre-commit framework](https://pre-commit.com/) and install the configured hooks on this repo via `pre-commit install`, or

MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ local_path_override(
1313

1414
# see https://registry.bazel.build/ for a list of available packages
1515

16-
bazel_dep(name = "platforms", version = "0.0.8")
16+
bazel_dep(name = "platforms", version = "0.0.9")
17+
bazel_dep(name = "rules_go", version = "0.47.0")
1718
bazel_dep(name = "rules_pkg", version = "0.10.1")
1819
bazel_dep(name = "rules_nodejs", version = "6.0.3")
1920
bazel_dep(name = "rules_python", version = "0.31.0")
2021
bazel_dep(name = "bazel_skylib", version = "1.5.0")
2122
bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
2223
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
2324
bazel_dep(name = "fmt", version = "10.0.0")
25+
bazel_dep(name = "gazelle", version = "0.36.0")
2426

2527
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
2628

@@ -52,6 +54,9 @@ node.toolchain(
5254
)
5355
use_repo(node, "nodejs", "nodejs_toolchains")
5456

57+
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
58+
go_sdk.download(version = "1.22.2")
59+
5560
register_toolchains(
5661
"@nodejs_toolchains//:all",
5762
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This open source repository contains the standard CodeQL libraries and queries t
44

55
## How do I learn CodeQL and run queries?
66

7-
There is [extensive documentation](https://codeql.github.com/docs/) on getting started with writing CodeQL using the [CodeQL extension for Visual Studio Code](https://codeql.github.com/docs/codeql-for-visual-studio-code/) and the [CodeQL CLI](https://codeql.github.com/docs/codeql-cli/).
7+
There is extensive documentation about the [CodeQL language](https://codeql.github.com/docs/), writing CodeQL using the [CodeQL extension for Visual Studio Code](https://docs.github.com/en/code-security/codeql-for-vs-code/) and using the [CodeQL CLI](https://docs.github.com/en/code-security/codeql-cli).
88

99
## Contributing
1010

cpp/ql/lib/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 0.13.0
2+
3+
### Breaking Changes
4+
5+
* Deleted the deprecated `GlobalValueNumberingImpl.qll` implementation.
6+
7+
### New Features
8+
9+
* Models-as-Data support has been added for C/C++. This feature allows flow sources, sinks and summaries to be expressed in compact strings as an alternative to modelling each source / sink / summary with explicit QL. See `dataflow/ExternalFlow.qll` for documentation and specification of the model format, and `models/implementations/ZMQ.qll` for a simple example of models. Importing models from `.yml` is not yet supported.
10+
11+
### Minor Analysis Improvements
12+
13+
* Source models have been added for the standard library function `getc` (and variations).
14+
* Source, sink and flow models for the ZeroMQ (ZMQ) networking library have been added.
15+
* Parameters of functions without definitions now have `ParameterNode`s.
16+
* The alias analysis used internally by various libraries has been improved to answer alias questions more conservatively. As a result, some queries may report fewer false positives.
17+
118
## 0.12.11
219

320
No user-facing changes.

cpp/ql/lib/change-notes/2024-04-05-sound-ir.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/ql/lib/change-notes/2024-04-18-param-nodes.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/ql/lib/change-notes/2024-10-04-getc.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/ql/lib/change-notes/2024-10-04-models-as-data.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/ql/lib/change-notes/2024-10-04-zmq.md

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## 0.13.0
2+
3+
### Breaking Changes
4+
5+
* Deleted the deprecated `GlobalValueNumberingImpl.qll` implementation.
6+
7+
### New Features
8+
9+
* Models-as-Data support has been added for C/C++. This feature allows flow sources, sinks and summaries to be expressed in compact strings as an alternative to modelling each source / sink / summary with explicit QL. See `dataflow/ExternalFlow.qll` for documentation and specification of the model format, and `models/implementations/ZMQ.qll` for a simple example of models. Importing models from `.yml` is not yet supported.
10+
11+
### Minor Analysis Improvements
12+
13+
* Source models have been added for the standard library function `getc` (and variations).
14+
* Source, sink and flow models for the ZeroMQ (ZMQ) networking library have been added.
15+
* Parameters of functions without definitions now have `ParameterNode`s.
16+
* The alias analysis used internally by various libraries has been improved to answer alias questions more conservatively. As a result, some queries may report fewer false positives.

cpp/ql/lib/codeql-pack.release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 0.12.11
2+
lastReleaseVersion: 0.13.0

cpp/ql/lib/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cpp-all
2-
version: 0.12.12-dev
2+
version: 0.13.1-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,27 @@ private predicate simple_comparison_eq(Instruction test, Operand op, int k, Abst
790790
exists(switch.getSuccessor(case)) and
791791
case.getValue().toInt() = k
792792
)
793+
or
794+
// There's no implicit CompareInstruction in files compiled as C since C
795+
// doesn't have implicit boolean conversions. So instead we check whether
796+
// there's a branch on a value of pointer or integer type.
797+
exists(ConditionalBranchInstruction branch, IRType type |
798+
not test instanceof CompareInstruction and
799+
type = test.getResultIRType() and
800+
(type instanceof IRAddressType or type instanceof IRIntegerType) and
801+
test = branch.getCondition() and
802+
op.getDef() = test
803+
|
804+
// We'd like to also include a case such as:
805+
// ```
806+
// k = 1 and
807+
// value.(BooleanValue).getValue() = true
808+
// ```
809+
// but all we know is that the value is non-zero in the true branch.
810+
// So we can only conclude something in the false branch.
811+
k = 0 and
812+
value.(BooleanValue).getValue() = false
813+
)
793814
}
794815

795816
private predicate complex_eq(
@@ -1156,5 +1177,14 @@ private predicate add_eq(
11561177
)
11571178
}
11581179

1180+
private class IntegerOrPointerConstantInstruction extends ConstantInstruction {
1181+
IntegerOrPointerConstantInstruction() {
1182+
this instanceof IntegerConstantInstruction or
1183+
this instanceof PointerConstantInstruction
1184+
}
1185+
}
1186+
11591187
/** The int value of integer constant expression. */
1160-
private int int_value(Instruction i) { result = i.(IntegerConstantInstruction).getValue().toInt() }
1188+
private int int_value(Instruction i) {
1189+
result = i.(IntegerOrPointerConstantInstruction).getValue().toInt()
1190+
}

0 commit comments

Comments
 (0)