Skip to content

Commit 11f08c8

Browse files
committed
Merge remote-tracking branch 'upstream/main' into next
2 parents f254174 + bc8a0eb commit 11f08c8

84 files changed

Lines changed: 978 additions & 276 deletions

File tree

Some content is hidden

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

‎.github/actions/install-codeql-packs/action.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ inputs:
77
The path to the CodeQL CLI directory.
88
required: false
99

10+
common_caches:
11+
description: |
12+
The path to the CodeQL common caches directory.
13+
required: false
14+
1015
mode:
1116
description: |
1217
The `--mode` option to `codeql pack install`.
@@ -22,4 +27,6 @@ runs:
2227
CODEQL_CLI: ${{ inputs.cli_path }}
2328
run: |
2429
PATH=$PATH:$CODEQL_CLI
25-
python scripts/install-packs.py --mode ${{ inputs.mode }}
30+
python scripts/install-packs.py \
31+
--mode ${{ inputs.mode }} \
32+
--common-caches "${{ inputs.common_caches }}"

‎.github/workflows/code-scanning-pack-gen.yml‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ env:
2020
XARGS_MAX_PROCS: 4
2121

2222
jobs:
23-
2423
prepare-code-scanning-pack-matrix:
2524
name: Prepare CodeQL Code Scanning pack matrix
2625
runs-on: ubuntu-22.04
@@ -62,10 +61,19 @@ jobs:
6261
codeql-home: ${{ github.workspace }}/codeql_home
6362
add-to-path: false
6463

64+
- name: Cache queries compilation
65+
id: cache-queries-compilation
66+
uses: actions/cache/restore@v6
67+
with:
68+
path: ${{ github.workspace }}/codeql_cache
69+
key: ${{ runner.os }}-codeql-compilation-code-scanning-pack-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}-${{ github.run_id }}
70+
restore-keys: ${{ runner.os }}-codeql-compilation-code-scanning-pack-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}
71+
6572
- name: Install CodeQL packs
6673
uses: ./.github/actions/install-codeql-packs
6774
with:
6875
cli_path: ${{ github.workspace }}/codeql_home/codeql
76+
common_caches: ${{ github.workspace }}/codeql_cache
6977

7078
- name: Determine ref for external help files
7179
id: determine-ref
@@ -105,11 +113,22 @@ jobs:
105113
PATH=$PATH:$CODEQL_HOME/codeql
106114
# Precompile all queries, and use a compilation cache larger than default
107115
# to ensure we cache all the queries for later steps
108-
codeql query compile --precompile --threads 0 --compilation-cache-size=1024 cpp c
116+
codeql query compile \
117+
--common-caches=${{ github.workspace }}/codeql_cache \
118+
--precompile \
119+
--threads 0 \
120+
--compilation-cache-size=1024 \
121+
cpp c
109122
110123
cd ..
111124
zip -r codeql-coding-standards/code-scanning-cpp-query-pack.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/configuration codeql-coding-standards/scripts/reports codeql-coding-standards/scripts/shared codeql-coding-standards/scripts/guideline_recategorization codeql-coding-standards/schemas
112125
126+
- name: Save queries compilation cache
127+
uses: actions/cache/save@v6
128+
with:
129+
path: ${{ github.workspace }}/codeql_cache
130+
key: ${{ steps.cache-queries-compilation.outputs.cache-primary-key }}
131+
113132
- name: Upload GHAS Query Pack
114133
uses: actions/upload-artifact@v7
115134
with:
@@ -119,20 +138,21 @@ jobs:
119138
- name: Create qlpack bundles
120139
env:
121140
CODEQL_HOME: ${{ github.workspace }}/codeql_home
141+
CODEQL_CACHE: ${{ github.workspace }}/codeql_cache
122142
run: |
123143
PATH=$PATH:$CODEQL_HOME/codeql
124144
125-
codeql pack bundle --output=common-cpp-coding-standards.tgz cpp/common/src
126-
codeql pack bundle --output=common-c-coding-standards.tgz c/common/src
127-
codeql pack bundle --output=misra-c-coding-standards.tgz c/misra/src
128-
codeql pack bundle --output=cert-c-coding-standards.tgz c/cert/src
129-
codeql pack bundle --output=cert-cpp-coding-standards.tgz cpp/cert/src
130-
codeql pack bundle --output=autosar-cpp-coding-standards.tgz cpp/autosar/src
131-
codeql pack bundle --output=misra-cpp-coding-standards.tgz cpp/misra/src
132-
codeql pack bundle --output=report-coding-standards.tgz cpp/report/src
145+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=common-cpp-coding-standards.tgz cpp/common/src
146+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=common-c-coding-standards.tgz c/common/src
147+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=misra-c-coding-standards.tgz c/misra/src
148+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=cert-c-coding-standards.tgz c/cert/src
149+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=cert-cpp-coding-standards.tgz cpp/cert/src
150+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=autosar-cpp-coding-standards.tgz cpp/autosar/src
151+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=misra-cpp-coding-standards.tgz cpp/misra/src
152+
codeql pack bundle --common-caches="$CODEQL_CACHE" --output=report-coding-standards.tgz cpp/report/src
133153
134154
- name: Upload qlpack bundles
135155
uses: actions/upload-artifact@v7
136156
with:
137157
name: coding-standards-codeql-packs
138-
path: '*-coding-standards.tgz'
158+
path: "*-coding-standards.tgz"

‎.github/workflows/codeql_unit_tests.yml‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ on:
1717
- "rc/**"
1818

1919
jobs:
20-
2120
prepare-unit-test-matrix:
2221
name: Prepare CodeQL unit test matrix
2322
runs-on: ubuntu-22.04
@@ -59,7 +58,7 @@ jobs:
5958

6059
- name: Cache CodeQL
6160
id: cache-codeql
62-
uses: actions/cache@v5
61+
uses: actions/cache@v6
6362
with:
6463
# A list of files, directories, and wildcard patterns to cache and restore
6564
path: ${{github.workspace}}/codeql_home
@@ -75,16 +74,34 @@ jobs:
7574
codeql-home: ${{ github.workspace }}/codeql_home
7675
add-to-path: false
7776

77+
- name: Cache queries compilation
78+
id: cache-queries-compilation
79+
uses: actions/cache/restore@v6
80+
with:
81+
path: ${{ github.workspace }}/codeql_cache
82+
key: ${{ runner.os }}-codeql-compilation-${{ matrix.language }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}-${{ github.run_id }}
83+
restore-keys: ${{ runner.os }}-codeql-compilation-${{ matrix.language }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}
84+
7885
- name: Install CodeQL packs
7986
uses: ./.github/actions/install-codeql-packs
8087
with:
8188
cli_path: ${{ github.workspace }}/codeql_home/codeql
89+
common_caches: ${{ github.workspace }}/codeql_cache
8290

8391
- name: Pre-Compile Queries
8492
id: pre-compile-queries
8593
run: |
86-
${{ github.workspace }}/codeql_home/codeql/codeql query compile --threads 0 ${{ matrix.language }}
87-
94+
${{ github.workspace }}/codeql_home/codeql/codeql query compile \
95+
--common-caches=${{ github.workspace }}/codeql_cache \
96+
--compilation-cache-size=1024 \
97+
--threads 0 \
98+
${{ matrix.language }}
99+
100+
- name: Save queries compilation cache
101+
uses: actions/cache/save@v6
102+
with:
103+
path: ${{ github.workspace }}/codeql_cache
104+
key: ${{ steps.cache-queries-compilation.outputs.cache-primary-key }}
88105

89106
- name: Run test suites
90107
id: run-test-suites
@@ -135,7 +152,7 @@ jobs:
135152
os.makedirs(os.path.dirname(test_report_path), exist_ok=True)
136153
test_report_file = open(test_report_path, 'w')
137154
files_to_close.append(test_report_file)
138-
procs.append(subprocess.Popen([codeql_bin, "test", "run", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", *test_roots], stdout=test_report_file, stderr=subprocess.PIPE))
155+
procs.append(subprocess.Popen([codeql_bin, "test", "run", "--common-caches=${{ github.workspace }}/codeql_cache", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", *test_roots], stdout=test_report_file, stderr=subprocess.PIPE))
139156
140157
for p in procs:
141158
_, err = p.communicate()

‎c/cert/src/codeql-pack.lock.yml‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ lockVersion: 1.0.0
33
dependencies:
44
advanced-security/qtil:
55
version: 0.0.3
6+
codeql/controlflow:
7+
version: 2.0.23
68
codeql/cpp-all:
7-
version: 5.0.0
9+
version: 6.1.4
810
codeql/dataflow:
9-
version: 2.0.8
11+
version: 2.0.23
1012
codeql/mad:
11-
version: 1.0.24
13+
version: 1.0.39
1214
codeql/quantum:
13-
version: 0.0.2
15+
version: 0.0.17
1416
codeql/rangeanalysis:
15-
version: 1.0.24
17+
version: 1.0.39
1618
codeql/ssa:
17-
version: 2.0.0
19+
version: 2.0.15
1820
codeql/tutorial:
19-
version: 1.0.24
21+
version: 1.0.39
2022
codeql/typeflow:
21-
version: 1.0.24
23+
version: 1.0.39
2224
codeql/typetracking:
23-
version: 2.0.8
25+
version: 2.0.23
2426
codeql/util:
25-
version: 2.0.11
27+
version: 2.0.26
2628
codeql/xml:
27-
version: 1.0.24
29+
version: 1.0.39
2830
compiled: false

‎c/cert/src/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ license: MIT
66
default-suite-file: codeql-suites/cert-c-default.qls
77
dependencies:
88
codeql/common-c-coding-standards: '*'
9-
codeql/cpp-all: 5.0.0
9+
codeql/cpp-all: 6.1.4

‎c/cert/src/rules/EXP37-C/DoNotCallFunctionsWithIncompatibleArguments.ql‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import cpp
2020
import codingstandards.c.cert
2121
import codingstandards.cpp.MistypedFunctionArguments
2222

23-
from FunctionCall fc, Function f, Parameter p
23+
from FunctionCall fc, Parameter p
2424
where
2525
not isExcluded(fc, ExpressionsPackage::doNotCallFunctionsWithIncompatibleArgumentsQuery()) and
26+
p = fc.getTarget().getAParameter() and
2627
(
27-
mistypedFunctionArguments(fc, f, p)
28+
mistypedFunctionArguments(fc, p)
2829
or
29-
complexArgumentPassedToRealParameter(fc, f, p)
30+
complexArgumentPassedToRealParameter(fc, p)
3031
)
3132
select fc,
32-
"Argument $@ in call to " + f.toString() + " is incompatible with parameter " + p.getTypedName() +
33-
".", fc.getArgument(p.getIndex()) as arg, arg.toString()
33+
"Argument $@ in " + fc.toString() + " is incompatible with parameter " + p.getTypedName() + ".",
34+
fc.getArgument(p.getIndex()) as arg, arg.toString()

‎c/cert/src/rules/MSC39-C/DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,64 @@
1818
import cpp
1919
import codingstandards.c.cert
2020
import codingstandards.cpp.Macro
21-
import semmle.code.cpp.dataflow.DataFlow
21+
import semmle.code.cpp.dataflow.new.DataFlow
22+
import semmle.code.cpp.ir.IR as IR
2223

23-
abstract class VaAccess extends Expr { }
24+
abstract class VaAccess extends VariableAccess {
25+
abstract DataFlow::Node getDfn();
26+
}
2427

2528
/**
2629
* The argument of a call to `va_arg`
2730
*/
2831
class VaArgArg extends VaAccess {
32+
IR::NextVarArgInstruction nva;
33+
2934
VaArgArg() { this = any(MacroInvocation m | m.getMacroName() = ["va_arg"]).getExpr().getChild(0) }
35+
36+
override DataFlow::Node getDfn() {
37+
// Simply using `DataFlow::exprNode(this)` will not correctly find the IR nodes for this
38+
// `va_arg` usage, so we have to dig into the IR here ourselves to properly wire things up.
39+
//
40+
// The IR for a `va_arg(p)` looks as follows:
41+
//
42+
// rx_n = VariableAddress[p]
43+
// ...
44+
// ry_0 = Load[p] : &:rx_n
45+
// ry_1 = Load[?] : &:ry_n
46+
// ry_2 = NextVarArg : ry_1
47+
//
48+
// The last occurrence of `va_list` that we have dataflow to is `ry_0` via an `OperandNode`,
49+
// and the simplest attachment between the AST and the IR is through `ry_2` and our parent AST
50+
// node, the `__builtin_vararg(...)` call.
51+
exists(IR::Operand ry0, IR::Instruction ry1, IR::NextVarArgInstruction ry2 |
52+
ry2.getAnOperand().getDef() = ry1 and
53+
ry2.getAst() = this.getParent() and
54+
ry1.getAnOperand() = ry0 and
55+
result.(DataFlow::OperandNode).getOperand() = ry0
56+
)
57+
}
3058
}
3159

3260
/**
3361
* The argument of a call to `va_end`
3462
*/
3563
class VaEndArg extends VaAccess {
3664
VaEndArg() { this = any(MacroInvocation m | m.getMacroName() = ["va_end"]).getExpr().getChild(0) }
65+
66+
override DataFlow::Node getDfn() { result.asExpr() = this }
3767
}
3868

3969
/**
40-
* Dataflow configuration for flow from a library function
41-
* to a call of function `asctime`
70+
* Dataflow configuration for flow from between `va_list` usages.
4271
*/
4372
module VaArgConfig implements DataFlow::ConfigSig {
4473
predicate isSource(DataFlow::Node src) {
4574
src.asUninitialized() =
4675
any(VariableDeclarationEntry m | m.getType().hasName("va_list")).getVariable()
4776
}
4877

49-
predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof VaAccess }
78+
predicate isSink(DataFlow::Node sink) { exists(VaAccess va_acc | sink = va_acc.getDfn()) }
5079
}
5180

5281
module VaArgFlow = DataFlow::Global<VaArgConfig>;
@@ -64,15 +93,15 @@ ControlFlowNode preceedsFC(VaAccess va_arg) {
6493
not result =
6594
any(MacroInvocation m |
6695
m.getMacroName() = ["va_start"] and
67-
m.getExpr().getChild(0).(VariableAccess).getTarget() = va_arg.(VariableAccess).getTarget()
96+
m.getExpr().getChild(0).(VariableAccess).getTarget() = va_arg.getTarget()
6897
).getExpr()
6998
)
7099
}
71100

72101
predicate sameSource(VaAccess e1, VaAccess e2) {
73102
exists(DataFlow::Node source |
74-
VaArgFlow::flow(source, DataFlow::exprNode(e1)) and
75-
VaArgFlow::flow(source, DataFlow::exprNode(e2))
103+
VaArgFlow::flow(source, e1.getDfn()) and
104+
VaArgFlow::flow(source, e2.getDfn())
76105
)
77106
}
78107

‎c/cert/test/codeql-pack.lock.yml‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ lockVersion: 1.0.0
33
dependencies:
44
advanced-security/qtil:
55
version: 0.0.3
6+
codeql/controlflow:
7+
version: 2.0.23
68
codeql/cpp-all:
7-
version: 5.0.0
9+
version: 6.1.4
810
codeql/dataflow:
9-
version: 2.0.8
11+
version: 2.0.23
1012
codeql/mad:
11-
version: 1.0.24
13+
version: 1.0.39
1214
codeql/quantum:
13-
version: 0.0.2
15+
version: 0.0.17
1416
codeql/rangeanalysis:
15-
version: 1.0.24
17+
version: 1.0.39
1618
codeql/ssa:
17-
version: 2.0.0
19+
version: 2.0.15
1820
codeql/tutorial:
19-
version: 1.0.24
21+
version: 1.0.39
2022
codeql/typeflow:
21-
version: 1.0.24
23+
version: 1.0.39
2224
codeql/typetracking:
23-
version: 2.0.8
25+
version: 2.0.23
2426
codeql/util:
25-
version: 2.0.11
27+
version: 2.0.26
2628
codeql/xml:
27-
version: 1.0.24
29+
version: 1.0.39
2830
compiled: false

‎c/cert/test/rules/MSC39-C/DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.expected‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:43,31-39)
2-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:44,22-30)
3-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:49,20-28)
4-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:52,20-28)
5-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:73,10-18)
6-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:74,29-37)
7-
WARNING: module 'DataFlow' has been deprecated and may be removed in future (DoNotCallVaArgOnAVaListThatHasAnIndeterminateValue.ql:75,29-37)
81
| test.c:23:32:23:33 | ap | The value of ap is indeterminate after the $@. | test.c:17:7:17:19 | call to contains_zero | call to contains_zero |
92
| test.c:26:10:26:11 | ap | The value of ap is indeterminate after the $@. | test.c:17:7:17:19 | call to contains_zero | call to contains_zero |
103
| test.c:39:12:39:13 | ap | The value of ap is indeterminate after the $@. | test.c:35:7:35:19 | call to contains_zero | call to contains_zero |

0 commit comments

Comments
 (0)