Skip to content

Commit da1a868

Browse files
committed
Merge branch 'main' into next
2 parents 1f6b8f9 + 5100d3e commit da1a868

File tree

385 files changed

+2526
-603
lines changed

Some content is hidden

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

385 files changed

+2526
-603
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
3636
repository: github/codeql-coding-standards-release-engineering
3737
event-type: matrix-test
38-
client-payload: '{"pr": "${{ github.event.number }}"}'
38+
client-payload: '{"pr": "${{ github.event.issue.number }}"}'
3939

4040
- uses: actions/github-script@v6
4141
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') }}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ _Carnegie Mellon and CERT are registered trademarks of Carnegie Mellon Universit
99
This repository contains CodeQL queries and libraries which support various Coding Standards for the [C++14](https://www.iso.org/standard/64029.html) programming language.
1010

1111
The following coding standards are supported:
12-
- [AUTOSAR - Guidelines for the use of C++14 language in critical and safety-related systems Release 20-11](https://www.autosar.org/fileadmin/standards/adaptive/20-11/AUTOSAR_RS_CPP14Guidelines.pdf)
13-
- [MISRA C++:2008](https://www.misra.org.uk) (support limited to the rules specified in AUTOSAR 20-11).
12+
- [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).
1414
- [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)
1515

1616
In addition, the following Coding Standards for the C programming language are under development:
@@ -50,3 +50,5 @@ All header files in [c/common/test/includes/standard-library](./c/common/test/in
5050
---
5151

5252
<sup>1</sup>This repository incorporates portions of the SEI CERT® Coding Standards available at https://wiki.sei.cmu.edu/confluence/display/seccode/SEI+CERT+Coding+Standards; however, such use does not necessarily constitute or imply an endorsement, recommendation, or favoring by Carnegie Mellon University or its Software Engineering Institute.
53+
54+

c/cert/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

c/cert/src/rules/ENV32-C/ExitHandlersMustReturnNormally.ql

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@
1414
import cpp
1515
import codingstandards.c.cert
1616

17-
class ExitFunction extends Function {
18-
ExitFunction() { this.hasGlobalName(["_Exit", "exit", "quick_exit", "longjmp"]) }
17+
/**
18+
* Exit function or macro.
19+
*/
20+
class Exit extends Locatable {
21+
Exit() {
22+
["_Exit", "exit", "quick_exit", "longjmp"] = [this.(Function).getName(), this.(Macro).getName()]
23+
}
1924
}
2025

21-
class ExitFunctionCall extends FunctionCall {
22-
ExitFunctionCall() { this.getTarget() instanceof ExitFunction }
26+
class ExitExpr extends Expr {
27+
ExitExpr() {
28+
this.(FunctionCall).getTarget() instanceof Exit
29+
or
30+
any(MacroInvocation m | this = m.getExpr()).getMacro() instanceof Exit
31+
}
2332
}
2433

34+
/**
35+
* Functions that are registered as exit handlers.
36+
*/
2537
class RegisteredAtexit extends FunctionAccess {
2638
RegisteredAtexit() {
2739
exists(FunctionCall ae |
@@ -32,24 +44,26 @@ class RegisteredAtexit extends FunctionAccess {
3244
}
3345

3446
/**
35-
* Nodes of type Function, FunctionCall or FunctionAccess that \
36-
* are reachable from a redistered atexit handler and
47+
* Nodes of type Function, FunctionCall, FunctionAccess or ExitExpr
48+
* that are reachable from a registered atexit handler and
3749
* can reach an exit function.
3850
*/
3951
class InterestingNode extends ControlFlowNode {
4052
InterestingNode() {
4153
exists(Function f |
4254
(
4355
this = f and
44-
// exit functions are not part of edges
45-
not this = any(ExitFunction ec)
56+
// exit is not part of edges
57+
not this instanceof Exit
4658
or
4759
this.(FunctionCall).getTarget() = f
4860
or
4961
this.(FunctionAccess).getTarget() = f
62+
or
63+
this.(ExitExpr).getEnclosingFunction() = f
5064
) and
51-
// reaches an exit function
52-
f.calls*(any(ExitFunction e)) and
65+
// reaches an `ExitExpr`
66+
f.calls*(any(ExitExpr ee).getEnclosingFunction()) and
5367
// is reachable from a registered atexit function
5468
exists(RegisteredAtexit re | re.getTarget().calls*(f))
5569
)
@@ -62,14 +76,12 @@ class InterestingNode extends ControlFlowNode {
6276
* `Function` and `FunctionCall` in their body.
6377
*/
6478
query predicate edges(InterestingNode a, InterestingNode b) {
65-
a.(FunctionAccess).getTarget() = b
66-
or
67-
a.(FunctionCall).getTarget() = b
68-
or
79+
a.(FunctionAccess).getTarget() = b or
80+
a.(FunctionCall).getTarget() = b or
6981
a.(Function).calls(_, b)
7082
}
7183

72-
from RegisteredAtexit hr, Function f, ExitFunctionCall e
84+
from RegisteredAtexit hr, Function f, ExitExpr e
7385
where edges(hr, f) and edges+(f, e)
7486
select f, hr, e, "The function is $@ and $@. It must instead terminate by returning.", hr,
7587
"registered as `exit handler`", e, "calls an `exit function`"

c/cert/src/rules/ERR33-C/DetectAndHandleStandardLibraryErrors.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ ControlFlowNode ferrorNotchecked(FileWriteFunctionCall write) {
441441
not isShortCircuitedEdge(mid, result) and
442442
result = mid.getASuccessor() and
443443
//Stop recursion on call to ferror on the correct file
444-
not accessSameTarget(result.(FerrorCall).getArgument(0), write.getFileExpr())
444+
not sameFileSource(result.(FerrorCall), write)
445445
)
446446
}
447447

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,26 @@ class FunctionWithRestrictParameters extends Function {
2525
Parameter restrictPtrParam;
2626

2727
FunctionWithRestrictParameters() {
28-
restrictPtrParam = this.getAParameter() and
2928
restrictPtrParam.getUnspecifiedType() instanceof PointerOrArrayType and
30-
restrictPtrParam.getType().hasSpecifier("restrict")
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+
)
3148
}
3249

3350
Parameter getARestrictPtrParam() { result = restrictPtrParam }

c/cert/src/rules/STR32-C/NonNullTerminatedToFunctionThatExpectsAString.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ CWE-123 – STR31-C =
271271

272272
## Implementation notes
273273

274-
None
274+
Wide character types are not handled correctly on the `aarch64le` architecture. This can lead to false negative alerts.
275275

276276
## References
277277

c/cert/src/rules/STR38-C/DoNotConfuseNarrowAndWideFunctions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Search for vulnerabilities resulting from the violation of this rule on the [CER
131131
132132
## Implementation notes
133133
134-
None
134+
Wide character types are not handled correctly on the `aarch64le` architecture. This can lead to false negative alerts.
135135
136136
## References
137137

c/cert/src/rules/STR38-C/DoNotConfuseNarrowAndWideFunctions.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,5 @@ where
6363
c instanceof WideToNarrowCast and actual = "wide" and expected = "narrow"
6464
)
6565
select call,
66-
"Call to function $@ with a " + actual + " character string $@ where a " + expected +
67-
" character string $@ is expected.", call.getTarget(), call.getTarget().getName(), arg,
68-
"argument", p, "parameter"
66+
"Call to function `" + call.getTarget().getName() + "` with a " + actual +
67+
" character string $@ where a " + expected + " character string is expected.", arg, "argument"

c/cert/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.18.0-dev
2+
version: 2.19.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

0 commit comments

Comments
 (0)