Skip to content

Commit 5ab9f13

Browse files
authored
Merge branch 'main' into rp/fix-796
2 parents 73c075d + 9dc1ca4 commit 5ab9f13

File tree

61 files changed

+944
-106
lines changed

Some content is hidden

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

61 files changed

+944
-106
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ jobs:
6868
- name: Determine ref for external help files
6969
id: determine-ref
7070
run: |
71-
if [[ $GITHUB_EVENT_NAME == "pull_request" || $GITHUB_EVENT_NAME == "merge_group" ]]; then
72-
echo "EXTERNAL_HELP_REF=$GITHUB_HEAD_REF" >> "$GITHUB_ENV"
71+
if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
72+
EXTERNAL_HELP_REF="${{ github.event.pull_request.base.ref }}"
73+
elif [[ $GITHUB_EVENT_NAME == "merge_group" ]]; then
74+
EXTERNAL_HELP_REF="${{ github.event.merge_group.base_ref }}"
7375
else
74-
echo "EXTERNAL_HELP_REF=$GITHUB_REF" >> "$GITHUB_ENV"
76+
EXTERNAL_HELP_REF="$GITHUB_REF"
7577
fi
78+
echo "EXTERNAL_HELP_REF=$EXTERNAL_HELP_REF" >> "$GITHUB_ENV"
7679
echo "Using ref $EXTERNAL_HELP_REF for external help files."
7780
7881
- name: Checkout external help files
79-
continue-on-error: true
8082
id: checkout-external-help-files
8183
uses: actions/checkout@v4
8284
with:

.github/workflows/codeql_unit_tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ jobs:
166166
steps:
167167
- name: Check if run-test-suites job failed to complete, if so fail
168168
if: ${{ needs.run-test-suites.result == 'failure' }}
169-
uses: actions/github-script@v3
169+
uses: actions/github-script@v7
170170
with:
171171
script: |
172172
core.setFailed('Test run job failed')

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
--json \
4141
-R github/codeql-coding-standards-release-engineering
4242
43-
- uses: actions/github-script@v6
43+
- uses: actions/github-script@v7
4444
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') && steps.check-write-permission.outputs.has-permission }}
4545
with:
4646
script: |

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
--json \
4141
-R github/codeql-coding-standards-release-engineering
4242
43-
- uses: actions/github-script@v6
43+
- uses: actions/github-script@v7
4444
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') && steps.check-write-permission.outputs.has-permission }}
4545
with:
4646
script: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.functiontypesnotinprototypeformshared.FunctionTypesNotInPrototypeFormShared
3+
4+
class TestFileQuery extends FunctionTypesNotInPrototypeFormSharedSharedQuery, TestQuery { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.missingstaticspecifierobjectredeclarationshared.MissingStaticSpecifierObjectRedeclarationShared
3+
4+
class TestFileQuery extends MissingStaticSpecifierObjectRedeclarationSharedSharedQuery, TestQuery {
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/call-to-obsolescent-function-gets
3+
* @name RULE-1-5: Disallowed usage of obsolescent function 'gets'
4+
* @description The function 'gets' is an obsolescent language feature which was removed in C11.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-1-5
9+
* external/misra/c/2012/amendment3
10+
* security
11+
* maintainability
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
18+
from FunctionCall fc
19+
where
20+
not isExcluded(fc, Language4Package::callToObsolescentFunctionGetsQuery()) and
21+
fc.getTarget().hasGlobalOrStdName("gets")
22+
select fc, "Call to obsolescent function 'gets'."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id c/misra/function-types-not-in-prototype-form-obsolete
3+
* @name RULE-1-5: Function types shall be in prototype form with named parameters
4+
* @description The use of non-prototype format parameter type declarators is an obsolescent
5+
* language feature.
6+
* @kind problem
7+
* @precision medium
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-1-5
10+
* correctness
11+
* external/misra/c/2012/amendment3
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
import codingstandards.cpp.rules.functiontypesnotinprototypeformshared.FunctionTypesNotInPrototypeFormShared
18+
19+
class FunctionTypesNotInPrototypeFormObsoleteQuery extends FunctionTypesNotInPrototypeFormSharedSharedQuery
20+
{
21+
FunctionTypesNotInPrototypeFormObsoleteQuery() {
22+
this = Language4Package::functionTypesNotInPrototypeFormObsoleteQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @id c/misra/invalid-define-or-undef-of-std-bool-macro
3+
* @name RULE-1-5: Programs may not undefine or redefine the macros bool, true, or false
4+
* @description Directives that undefine and/or redefine the standard boolean macros has been
5+
* declared an obsolescent language feature since C99.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity warning
9+
* @tags external/misra/id/rule-1-5
10+
* maintainability
11+
* readability
12+
* external/misra/c/2012/amendment3
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.c.misra
18+
19+
string getABoolMacroName() { result = ["true", "false", "bool"] }
20+
21+
from PreprocessorDirective directive, string opString, string macroName
22+
where
23+
not isExcluded(directive, Language4Package::invalidDefineOrUndefOfStdBoolMacroQuery()) and
24+
macroName = getABoolMacroName() and
25+
(
26+
macroName = directive.(Macro).getName() and
27+
opString = "define"
28+
or
29+
macroName = directive.(PreprocessorUndef).getName() and
30+
opString = "undefine"
31+
)
32+
select directive, "Invalid " + opString + " of boolean standard macro '" + macroName + "'."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id c/misra/missing-static-specifier-func-redeclaration-obsolete
3+
* @name RULE-1-5: If a function has internal linkage then all re-declarations shall include the static storage class
4+
* @description Declaring a function with internal linkage without the static storage class
5+
* specifier is an obselescent feature.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity warning
9+
* @tags external/misra/id/rule-1-5
10+
* readability
11+
* external/misra/c/2012/amendment3
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
import codingstandards.cpp.rules.missingstaticspecifierfunctionredeclarationshared.MissingStaticSpecifierFunctionRedeclarationShared
18+
19+
class MissingStaticSpecifierFuncRedeclarationObsoleteQuery extends MissingStaticSpecifierFunctionRedeclarationSharedSharedQuery
20+
{
21+
MissingStaticSpecifierFuncRedeclarationObsoleteQuery() {
22+
this = Language4Package::missingStaticSpecifierFuncRedeclarationObsoleteQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id c/misra/missing-static-specifier-object-redeclaration-obsolete
3+
* @name RULE-1-5: If an object has internal linkage then all re-declarations shall include the static storage class
4+
* @description Declaring an identifier with internal linkage without the static storage class
5+
* specifier is an obselescent feature.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity warning
9+
* @tags external/misra/id/rule-1-5
10+
* readability
11+
* external/misra/c/2012/amendment3
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
import codingstandards.cpp.rules.missingstaticspecifierobjectredeclarationshared.MissingStaticSpecifierObjectRedeclarationShared
18+
19+
class MissingStaticSpecifierObjectRedeclarationObsoleteQuery extends MissingStaticSpecifierObjectRedeclarationSharedSharedQuery
20+
{
21+
MissingStaticSpecifierObjectRedeclarationObsoleteQuery() {
22+
this = Language4Package::missingStaticSpecifierObjectRedeclarationObsoleteQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id c/misra/size-in-realloc-call-is-zero
3+
* @name RULE-1-5: Size argument value in realloc call is equal zero
4+
* @description Invoking realloc with a size argument set to zero is implementation-defined behavior
5+
* and declared as an obsolete feature in C18.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-1-5
10+
* correctness
11+
* external/misra/c/2012/amendment3
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
import semmle.code.cpp.rangeanalysis.new.RangeAnalysis
18+
import codingstandards.cpp.Realloc
19+
20+
from ReallocCall call
21+
where
22+
not isExcluded(call, Language4Package::sizeInReallocCallIsZeroQuery()) and
23+
call.sizeIsExactlyZero()
24+
select call,
25+
"Size argument '$@' may equal zero in realloc call, resulting in obsolescent and/or implementation-defined behavior.",
26+
call.getSizeArgument(), call.getSizeArgument().toString()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id c/misra/size-in-realloc-call-may-be-zero
3+
* @name RULE-1-5: Size argument value in realloc call may equal zero
4+
* @description Invoking realloc with a size argument set to zero is implementation-defined behavior
5+
* and declared as an obsolete feature in C18.
6+
* @kind problem
7+
* @precision medium
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-1-5
10+
* correctness
11+
* external/misra/c/2012/amendment3
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
import codingstandards.cpp.Realloc
18+
19+
from ReallocCall call
20+
where
21+
not isExcluded(call, Language4Package::sizeInReallocCallMayBeZeroQuery()) and
22+
call.sizeMayBeZero() and
23+
not call.sizeIsExactlyZero()
24+
select call,
25+
"Size argument '$@' equals zero in realloc call, resulting in obsolescent and/or implementation-defined behavior.",
26+
call.getSizeArgument(), call.getSizeArgument().toString()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @id c/misra/ungetc-call-on-stream-position-zero
3+
* @name RULE-1-5: Disallowed obsolescent usage of 'ungetc' on a file stream at position zero
4+
* @description Calling the function 'ungetc' on a file stream with a position of zero is an
5+
* obsolescent language feature.
6+
* @kind path-problem
7+
* @precision high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-1-5
10+
* external/misra/c/2012/amendment3
11+
* security
12+
* maintainability
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import semmle.code.cpp.dataflow.new.DataFlow
18+
import semmle.code.cpp.controlflow.Dominance
19+
import codingstandards.c.misra
20+
21+
/**
22+
* This is an inconclusive list, which is adequate, as RULE-21-3 provides
23+
* assurance we won't have false negatives, or care too much about false
24+
* positives.
25+
*/
26+
class MoveStreamPositionCall extends FunctionCall {
27+
Expr streamArgument;
28+
29+
MoveStreamPositionCall() {
30+
getTarget().hasGlobalOrStdName("fgetc") and
31+
streamArgument = getArgument(0)
32+
or
33+
getTarget().hasGlobalOrStdName("getc") and
34+
streamArgument = getArgument(0)
35+
or
36+
getTarget().hasGlobalOrStdName("fget") and
37+
streamArgument = getArgument(2)
38+
or
39+
getTarget().hasGlobalOrStdName("fscanf") and
40+
streamArgument = getArgument(0)
41+
or
42+
getTarget().hasGlobalOrStdName("fsetpos") and
43+
streamArgument = getArgument(0)
44+
or
45+
getTarget().hasGlobalOrStdName("fseek") and
46+
streamArgument = getArgument(0)
47+
or
48+
getTarget().hasGlobalOrStdName("fread") and
49+
streamArgument = getArgument(3)
50+
}
51+
52+
Expr getStreamArgument() { result = streamArgument }
53+
}
54+
55+
module FilePositionZeroFlowConfig implements DataFlow::ConfigSig {
56+
predicate isSource(DataFlow::Node node) {
57+
node.asIndirectExpr().(FunctionCall).getTarget().hasGlobalOrStdName("fopen")
58+
}
59+
60+
predicate isSink(DataFlow::Node node) {
61+
exists(FunctionCall fc |
62+
fc.getTarget().hasGlobalOrStdName("ungetc") and
63+
node.asIndirectExpr() = fc.getArgument(1)
64+
)
65+
}
66+
67+
predicate isBarrierIn(DataFlow::Node node) {
68+
exists(MoveStreamPositionCall fc | node.asIndirectExpr() = fc.getStreamArgument())
69+
}
70+
}
71+
72+
module FilePositionZeroFlow = DataFlow::Global<FilePositionZeroFlowConfig>;
73+
74+
import FilePositionZeroFlow::PathGraph
75+
76+
from FilePositionZeroFlow::PathNode sink, FilePositionZeroFlow::PathNode source
77+
where
78+
not isExcluded(sink.getNode().asExpr(), Language4Package::ungetcCallOnStreamPositionZeroQuery()) and
79+
FilePositionZeroFlow::flowPath(source, sink)
80+
select sink.getNode(), source, sink,
81+
"Obsolescent call to ungetc on file stream $@ at position zero.", source, source.toString()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id c/misra/use-of-obsolete-macro-atomic-var-init
3+
* @name RULE-1-5: Disallowed usage of obsolete macro ATOMIC_VAR_INIT compiled as C18
4+
* @description The macro ATOMIC_VAR_INIT is has been declared an obsolescent language feature since
5+
* C18.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity recommendation
9+
* @tags external/misra/id/rule-1-5
10+
* maintainability
11+
* readability
12+
* external/misra/c/2012/amendment3
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.c.misra
18+
19+
from MacroInvocation invoke
20+
where
21+
not isExcluded(invoke, Language4Package::useOfObsoleteMacroAtomicVarInitQuery()) and
22+
invoke.getMacroName() = "ATOMIC_VAR_INIT"
23+
select invoke,
24+
"Usage of macro ATOMIC_VAR_INIT() is declared obscelescent in C18, and discouraged in earlier C versions."

0 commit comments

Comments
 (0)