Skip to content

Commit b5a7210

Browse files
committed
Merge remote-tracking branch 'upstream/main' into next
2 parents c69c7b8 + 4345ca0 commit b5a7210

File tree

912 files changed

+11754
-2061
lines changed

Some content is hidden

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

912 files changed

+11754
-2061
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
codeql query compile --precompile --threads 0 c
104104
105105
cd ..
106-
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/scripts/shared codeql-coding-standards/scripts/schemas
106+
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
107107
108108
- name: Upload GHAS Query Pack
109109
uses: actions/upload-artifact@v2
+8-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: 🤖 Run Matrix Check
1+
name: 🤖 Run Matrix Check
22

33
on:
44
pull_request_target:
5-
types: [synchronize,opened]
5+
types: [synchronize, opened]
66
branches:
77
- "matrix/**"
88
workflow_dispatch:
@@ -11,29 +11,27 @@ jobs:
1111
dispatch-matrix-check:
1212
runs-on: ubuntu-22.04
1313
steps:
14-
1514
- name: Test Variables
1615
shell: pwsh
1716
run: |
18-
Write-Host "Running as: ${{github.actor}}"
19-
17+
Write-Host "Running as: ${{github.actor}}"
18+
2019
- name: Dispatch Matrix Testing Job
21-
if: ${{ contains(fromJSON('["jsinglet", "mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "kraiouchkine"]'), github.actor) }}
20+
if: ${{ contains(fromJSON('["mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill"]'), github.actor) }}
2221
uses: peter-evans/repository-dispatch@v2
2322
with:
2423
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
2524
repository: github/codeql-coding-standards-release-engineering
2625
event-type: matrix-test
27-
client-payload: '{"pr": "${{ github.event.number }}"}'
28-
26+
client-payload: '{"pr": "${{ github.event.number }}"}'
2927

3028
- uses: actions/github-script@v6
31-
if: ${{ contains(fromJSON('["jsinglet", "mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "kraiouchkine"]'), github.actor) }}
29+
if: ${{ contains(fromJSON('["mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill"]'), github.actor) }}
3230
with:
3331
script: |
3432
github.rest.issues.createComment({
3533
issue_number: context.issue.number,
3634
owner: context.repo.owner,
3735
repo: context.repo.repo,
3836
body: '🤖 Beep Boop! Matrix Testing for this PR has been initiated. Please check back later for results. <br><br> :bulb: If you do not hear back from me please check my status! **I will report even if this PR does not contain files eligible for matrix testing.**'
39-
})
37+
})

.github/workflows/dispatch-matrix-test-on-comment.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,23 @@ on:
88
- "rc/**"
99
- next
1010

11-
1211
jobs:
1312
dispatch-matrix-check:
1413
runs-on: ubuntu-22.04
1514
steps:
16-
1715
- name: Test Variables
1816
shell: pwsh
1917
run: |
2018
Write-Host "Running as: ${{github.actor}}"
2119
2220
$actor = "${{github.actor}}"
2321
24-
$acl = @("jsinglet","mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "kraiouchkine")
22+
$acl = @("mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill")
2523
2624
if(-not ($actor -in $acl)){
2725
throw "Refusing to run workflow for user not in acl."
2826
}
2927
30-
3128
- name: Dispatch Matrix Testing Job
3229
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') }}
3330
uses: peter-evans/repository-dispatch@v2

.github/workflows/dispatch-release-performance-check.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ jobs:
1212
dispatch-matrix-check:
1313
runs-on: ubuntu-22.04
1414
steps:
15-
1615
- name: Test Variables
1716
shell: pwsh
1817
run: |
1918
Write-Host "Running as: ${{github.actor}}"
2019
2120
$actor = "${{github.actor}}"
2221
23-
$acl = @("jsinglet","mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "kraiouchkine")
22+
$acl = @("mbaluda", "lcartey", "rvermeulen", "ravikprasad", "jeongsoolee09", "hohn", "knewbury01", "nicolaswill")
2423
2524
if(-not ($actor -in $acl)){
2625
throw "Refusing to run workflow for user not in acl."
@@ -33,8 +32,7 @@ jobs:
3332
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
3433
repository: github/codeql-coding-standards-release-engineering
3534
event-type: performance-test
36-
client-payload: '{"pr": "${{ github.event.issue.number }}"}'
37-
35+
client-payload: '{"pr": "${{ github.event.issue.number }}"}'
3836

3937
- uses: actions/github-script@v6
4038
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') }}
@@ -45,4 +43,4 @@ jobs:
4543
owner: context.repo.owner,
4644
repo: context.repo.repo,
4745
body: '🏁 Beep Boop! Performance testing for this PR has been initiated. Please check back later for results. Note that the query package generation step must complete before testing will start so it might be a minute. <br><br> :bulb: If you do not hear back from me please check my status! **I will report even if I fail!**'
48-
})
46+
})

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ This repository contains CodeQL queries and libraries which support various Codi
1010

1111
The following coding standards are supported:
1212
- [AUTOSAR - Guidelines for the use of C++14 language in critical and safety-related systems (Releases R22-11, R20-11, R19-11 and R19-03)](https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSAR_RS_CPP14Guidelines.pdf).
13-
- [MISRA C++:2008](https://www.misra.org.uk) (support limited to the rules specified in AUTOSAR).
1413
- [SEI CERT C++ Coding Standard: Rules for Developing Safe, Reliable, and Secure Systems (2016 Edition)](https://resources.sei.cmu.edu/library/asset-view.cfm?assetID=494932)
1514
- [SEI CERT C Coding Standard: Rules for Developing Safe, Reliable, and Secure Systems (2016 Edition)](https://resources.sei.cmu.edu/downloads/secure-coding/assets/sei-cert-c-coding-standard-2016-v01.pdf)
16-
- [MISRA C 2012](https://www.misra.org.uk/product/misra-c2012-third-edition-first-revision/).
15+
- [MISRA C 2012, 3rd Edition, 1st revision](https://www.misra.org.uk/product/misra-c2012-third-edition-first-revision/) (incoporating Amendment 1 & Technical Corrigendum 1). In addition, we support the following additional amendments and technical corrigendums:
16+
- [MISRA C 2012 Amendment 2](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD2.pdf)
17+
- [MISRA C 2012 Technical Corrigendum 2](https://misra.org.uk/app/uploads/2022/04/MISRA-C-2012-TC2.pdf)
18+
19+
## :construction: Standards under development :construction:
20+
21+
- [MISRA C++ 2023](https://misra.org.uk/product/misra-cpp2023/) - under development _scheduled for release 2024 Q4_.
1722

1823
## How do I use the CodeQL Coding Standards Queries?
1924

c/cert/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.29.0-dev
2+
version: 2.35.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

c/cert/src/rules/ARR39-C/DoNotAddOrSubtractAScaledIntegerToAPointer.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import cpp
1515
import codingstandards.c.cert
16-
import codingstandards.c.Pointers
16+
import codingstandards.cpp.Pointers
1717
import semmle.code.cpp.dataflow.TaintTracking
1818
import ScaledIntegerPointerArithmeticFlow::PathGraph
1919

c/cert/src/rules/EXP43-C/DoNotPassAliasedPointerToRestrictQualifiedParam.ql

+5-171
Original file line numberDiff line numberDiff line change
@@ -12,177 +12,11 @@
1212

1313
import cpp
1414
import codingstandards.c.cert
15-
import codingstandards.c.Pointers
16-
import codingstandards.c.Variable
17-
import semmle.code.cpp.dataflow.DataFlow
18-
import semmle.code.cpp.pointsto.PointsTo
19-
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
15+
import codingstandards.cpp.rules.donotpassaliasedpointertorestrictqualifiedparamshared.DoNotPassAliasedPointerToRestrictQualifiedParamShared
2016

21-
/**
22-
* A function that has a parameter with a restrict-qualified pointer type.
23-
*/
24-
class FunctionWithRestrictParameters extends Function {
25-
Parameter restrictPtrParam;
26-
27-
FunctionWithRestrictParameters() {
28-
restrictPtrParam.getUnspecifiedType() instanceof PointerOrArrayType and
29-
(
30-
restrictPtrParam.getType().hasSpecifier(["restrict"]) and
31-
restrictPtrParam = this.getAParameter()
32-
or
33-
this.hasGlobalName(["strcpy", "strncpy", "strcat", "strncat", "memcpy"]) and
34-
restrictPtrParam = this.getParameter([0, 1])
35-
or
36-
this.hasGlobalName(["strcpy_s", "strncpy_s", "strcat_s", "strncat_s", "memcpy_s"]) and
37-
restrictPtrParam = this.getParameter([0, 2])
38-
or
39-
this.hasGlobalName(["strtok_s"]) and
40-
restrictPtrParam = this.getAParameter()
41-
or
42-
this.hasGlobalName(["printf", "printf_s", "scanf", "scanf_s"]) and
43-
restrictPtrParam = this.getParameter(0)
44-
or
45-
this.hasGlobalName(["sprintf", "sprintf_s", "snprintf", "snprintf_s"]) and
46-
restrictPtrParam = this.getParameter(3)
47-
)
48-
}
49-
50-
Parameter getARestrictPtrParam() { result = restrictPtrParam }
51-
}
52-
53-
/**
54-
* A call to a function that has a parameter with a restrict-qualified pointer type.
55-
*/
56-
class CallToFunctionWithRestrictParameters extends FunctionCall {
57-
CallToFunctionWithRestrictParameters() {
58-
this.getTarget() instanceof FunctionWithRestrictParameters
59-
}
60-
61-
Expr getARestrictPtrArg() {
62-
result =
63-
this.getArgument(this.getTarget()
64-
.(FunctionWithRestrictParameters)
65-
.getARestrictPtrParam()
66-
.getIndex())
67-
}
68-
69-
Expr getAPtrArg(int index) {
70-
result = this.getArgument(index) and
71-
pointerValue(result)
72-
}
73-
74-
Expr getAPossibleSizeArg() {
75-
exists(Parameter param |
76-
param = this.getTarget().(FunctionWithRestrictParameters).getAParameter() and
77-
param.getUnderlyingType() instanceof IntegralType and
78-
// exclude __builtin_object_size
79-
not result.(FunctionCall).getTarget() instanceof BuiltInFunction and
80-
result = this.getArgument(param.getIndex())
81-
)
82-
}
83-
}
84-
85-
/**
86-
* A `PointsToExpr` that is an argument of a pointer-type in a `CallToFunctionWithRestrictParameters`
87-
*/
88-
class CallToFunctionWithRestrictParametersArgExpr extends Expr {
89-
int paramIndex;
90-
91-
CallToFunctionWithRestrictParametersArgExpr() {
92-
this = any(CallToFunctionWithRestrictParameters call).getAPtrArg(paramIndex)
17+
class DoNotPassAliasedPointerToRestrictQualifiedParamQuery extends DoNotPassAliasedPointerToRestrictQualifiedParamSharedSharedQuery
18+
{
19+
DoNotPassAliasedPointerToRestrictQualifiedParamQuery() {
20+
this = Pointers3Package::doNotPassAliasedPointerToRestrictQualifiedParamQuery()
9321
}
94-
95-
int getParamIndex() { result = paramIndex }
96-
}
97-
98-
int getStatedValue(Expr e) {
99-
// `upperBound(e)` defaults to `exprMaxVal(e)` when `e` isn't analyzable. So to get a meaningful
100-
// result in this case we pick the minimum value obtainable from dataflow and range analysis.
101-
result =
102-
upperBound(e)
103-
.minimum(min(Expr source | DataFlow::localExprFlow(source, e) | source.getValue().toInt()))
104-
}
105-
106-
int getPointerArithmeticOperandStatedValue(CallToFunctionWithRestrictParametersArgExpr expr) {
107-
result = getStatedValue(expr.(PointerArithmeticExpr).getOperand())
108-
or
109-
// edge-case: &(array[index]) expressions
110-
result = getStatedValue(expr.(AddressOfExpr).getOperand().(PointerArithmeticExpr).getOperand())
111-
or
112-
// fall-back if `expr` is not a pointer arithmetic expression
113-
not expr instanceof PointerArithmeticExpr and
114-
not expr.(AddressOfExpr).getOperand() instanceof PointerArithmeticExpr and
115-
result = 0
11622
}
117-
118-
module PointerValueToRestrictArgConfig implements DataFlow::ConfigSig {
119-
predicate isSource(DataFlow::Node source) { pointerValue(source.asExpr()) }
120-
121-
predicate isSink(DataFlow::Node sink) {
122-
exists(CallToFunctionWithRestrictParameters call |
123-
sink.asExpr() = call.getAPtrArg(_).getAChild*()
124-
)
125-
}
126-
127-
predicate isBarrierIn(DataFlow::Node node) {
128-
exists(AddressOfExpr a | node.asExpr() = a.getOperand().getAChild*())
129-
}
130-
}
131-
132-
module PointerValueToRestrictArgFlow = DataFlow::Global<PointerValueToRestrictArgConfig>;
133-
134-
from
135-
CallToFunctionWithRestrictParameters call, CallToFunctionWithRestrictParametersArgExpr arg1,
136-
CallToFunctionWithRestrictParametersArgExpr arg2, int argOffset1, int argOffset2, Expr source1,
137-
Expr source2, string sourceMessage1, string sourceMessage2
138-
where
139-
not isExcluded(call, Pointers3Package::doNotPassAliasedPointerToRestrictQualifiedParamQuery()) and
140-
arg1 = call.getARestrictPtrArg() and
141-
arg2 = call.getAPtrArg(_) and
142-
// enforce ordering to remove permutations if multiple restrict-qualified args exist
143-
(not arg2 = call.getARestrictPtrArg() or arg2.getParamIndex() > arg1.getParamIndex()) and
144-
(
145-
// check if two pointers address the same object
146-
PointerValueToRestrictArgFlow::flow(DataFlow::exprNode(source1),
147-
DataFlow::exprNode(arg1.getAChild*())) and
148-
(
149-
// one pointer value flows to both args
150-
PointerValueToRestrictArgFlow::flow(DataFlow::exprNode(source1),
151-
DataFlow::exprNode(arg2.getAChild*())) and
152-
sourceMessage1 = "$@" and
153-
sourceMessage2 = "source" and
154-
source1 = source2
155-
or
156-
// there are two separate values that flow from an AddressOfExpr of the same target
157-
getAddressOfExprTargetBase(source1) = getAddressOfExprTargetBase(source2) and
158-
PointerValueToRestrictArgFlow::flow(DataFlow::exprNode(source2),
159-
DataFlow::exprNode(arg2.getAChild*())) and
160-
sourceMessage1 = "a pair of address-of expressions ($@, $@)" and
161-
sourceMessage2 = "addressof1" and
162-
not source1 = source2
163-
)
164-
) and
165-
// get the offset of the pointer arithmetic operand (or '0' if there is none)
166-
argOffset1 = getPointerArithmeticOperandStatedValue(arg1) and
167-
argOffset2 = getPointerArithmeticOperandStatedValue(arg2) and
168-
(
169-
// case 1: the pointer args are the same.
170-
// (definite aliasing)
171-
argOffset1 = argOffset2
172-
or
173-
// case 2: the pointer args are different, a size arg exists,
174-
// and the size arg is greater than the difference between the offsets.
175-
// (potential aliasing)
176-
exists(Expr sizeArg |
177-
sizeArg = call.getAPossibleSizeArg() and
178-
getStatedValue(sizeArg) > (argOffset1 - argOffset2).abs()
179-
)
180-
or
181-
// case 3: the pointer args are different, and a size arg does not exist
182-
// (potential aliasing)
183-
not exists(call.getAPossibleSizeArg())
184-
)
185-
select call,
186-
"Call to '" + call.getTarget().getName() + "' passes an $@ to a $@ (pointer value derived from " +
187-
sourceMessage1 + ".", arg2, "aliased pointer", arg1, "restrict-qualified parameter", source1,
188-
sourceMessage2, source2, "addressof2"

c/cert/src/rules/EXP43-C/RestrictPointerReferencesOverlappingObject.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import cpp
1414
import semmle.code.cpp.dataflow.DataFlow
1515
import semmle.code.cpp.controlflow.Dominance
1616
import codingstandards.c.cert
17-
import codingstandards.c.Variable
17+
import codingstandards.cpp.Variable
1818

1919
/**
2020
* An `Expr` that is an assignment or initialization to a restrict-qualified pointer-type variable.

c/cert/src/rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql

+7-20
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,11 @@
1515

1616
import cpp
1717
import codingstandards.c.cert
18-
import codingstandards.cpp.Overflow
19-
import semmle.code.cpp.controlflow.Guards
20-
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
18+
import codingstandards.cpp.rules.unsignedoperationwithconstantoperandswraps.UnsignedOperationWithConstantOperandsWraps
2119

22-
from InterestingOverflowingOperation op
23-
where
24-
not isExcluded(op, IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery()) and
25-
op.getType().getUnderlyingType().(IntegralType).isUnsigned() and
26-
// Not within a guard condition
27-
not exists(GuardCondition gc | gc.getAChild*() = op) and
28-
// Not guarded by a check, where the check is not an invalid overflow check
29-
not op.hasValidPreCheck() and
30-
// Is not checked after the operation
31-
not op.hasValidPostCheck() and
32-
// Permitted by exception 3
33-
not op instanceof LShiftExpr and
34-
// Permitted by exception 2 - zero case is handled in separate query
35-
not op instanceof DivExpr and
36-
not op instanceof RemExpr
37-
select op,
38-
"Operation " + op.getOperator() + " of type " + op.getType().getUnderlyingType() + " may wrap."
20+
class UnsignedIntegerOperationsWrapAroundQuery extends UnsignedOperationWithConstantOperandsWrapsSharedQuery
21+
{
22+
UnsignedIntegerOperationsWrapAroundQuery() {
23+
this = IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery()
24+
}
25+
}

0 commit comments

Comments
 (0)