Skip to content

Commit b70f2e1

Browse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/implement-types2-package
2 parents 985af96 + e18d80f commit b70f2e1

File tree

49 files changed

+468
-63
lines changed

Some content is hidden

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

49 files changed

+468
-63
lines changed

.github/workflows/validate-package-files.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ jobs:
5656
find rule_packages/$LANGUAGE -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py $LANGUAGE
5757
git diff
5858
git diff --compact-summary
59-
git diff --quiet
59+
git diff --quiet
60+
61+
- name: Validate Amendments
62+
env:
63+
LANGUAGE: ${{ matrix.language }}
64+
run: |
65+
python scripts/validate-amendments-csv.py $LANGUAGE

amendments.csv

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
language,standard,amendment,rule_id,supportable,implementation_category,implemented,difficulty
2+
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,No,Easy
3+
c,MISRA-C-2012,Amendment3,DIR-4-9,Yes,Refine,No,Easy
4+
c,MISRA-C-2012,Amendment3,DIR-4-11,Yes,Refine,No,Import
5+
c,MISRA-C-2012,Amendment3,RULE-1-4,Yes,Replace,No,Easy
6+
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,No,Easy
7+
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,No,Easy
8+
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,No,Import
9+
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,No,Easy
10+
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,No,Import
11+
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,No,Import
12+
c,MISRA-C-2012,Amendment3,RULE-21-11,Yes,Clarification,No,Import
13+
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,No,Easy
14+
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,No,Easy
15+
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,No,Easy
16+
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,No,Very Hard
17+
c,MISRA-C-2012,Amendment4,RULE-18-6,Yes,Expand,No,Medium
18+
c,MISRA-C-2012,Amendment4,RULE-18-8,Yes,Split,No,Easy
19+
c,MISRA-C-2012,Corrigendum2,RULE-2-2,Yes,Clarification,No,Import
20+
c,MISRA-C-2012,Corrigendum2,RULE-2-7,Yes,Clarification,No,Import
21+
c,MISRA-C-2012,Corrigendum2,RULE-3-1,Yes,Refine,No,Easy
22+
c,MISRA-C-2012,Corrigendum2,RULE-8-6,Yes,Clarification,No,Import
23+
c,MISRA-C-2012,Corrigendum2,RULE-8-9,Yes,Clarification,No,Import
24+
c,MISRA-C-2012,Corrigendum2,RULE-9-4,Yes,Clarification,No,Import
25+
c,MISRA-C-2012,Corrigendum2,RULE-10-1,Yes,Clarification,No,Import
26+
c,MISRA-C-2012,Corrigendum2,RULE-18-3,Yes,Clarification,No,Import
27+
c,MISRA-C-2012,Corrigendum2,RULE-1-4,Yes,Replace,No,Easy
28+
c,MISRA-C-2012,Corrigendum2,RULE-9-1,Yes,Refine,No,Easy
29+
c,MISRA-C-2012,Corrigendum2,RULE-9-2,Yes,Refine,No,Import
30+
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,No,Import
31+
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,No,Easy
32+
c,MISRA-C-2012,Corrigendum2,RULE-8-2,Yes,Clarification,No,Import
33+
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,No,Easy
34+
c,MISRA-C-2012,Corrigendum2,RULE-8-7,Yes,Clarification,No,Import
35+
c,MISRA-C-2012,Corrigendum2,RULE-10-2,Yes,Refine,No,Easy
36+
c,MISRA-C-2012,Corrigendum2,RULE-10-3,Yes,Clarification,No,Import
37+
c,MISRA-C-2012,Corrigendum2,RULE-11-3,Yes,Clarification,No,Import
38+
c,MISRA-C-2012,Corrigendum2,RULE-11-6,Yes,Clarification,No,Import
39+
c,MISRA-C-2012,Corrigendum2,RULE-13-2,Yes,Clarification,No,Import
40+
c,MISRA-C-2012,Corrigendum2,RULE-13-6,Yes,Clarification,No,Import
41+
c,MISRA-C-2012,Corrigendum2,RULE-14-3,Yes,Refine,No,Easy
42+
c,MISRA-C-2012,Corrigendum2,RULE-15-7,Yes,Clarification,No,Import
43+
c,MISRA-C-2012,Corrigendum2,RULE-17-4,Yes,Clarification,No,Import
44+
c,MISRA-C-2012,Corrigendum2,RULE-17-5,Yes,Clarification,No,Import
45+
c,MISRA-C-2012,Corrigendum2,RULE-18-1,Yes,Refine,No,Easy
46+
c,MISRA-C-2012,Corrigendum2,RULE-20-14,No,Clarification,No,Import
47+
c,MISRA-C-2012,Corrigendum2,RULE-21-19,Yes,Clarification,No,Import
48+
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,No,Easy
49+
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,No,Import

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.35.0-dev
2+
version: 2.36.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

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.35.0-dev
2+
version: 2.36.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

c/common/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

c/common/test/qlpack.yml

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

c/misra/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
description: MISRA C 2012
44
suites: codeql-suites
55
license: MIT

c/misra/src/rules/RULE-11-4/ConversionBetweenPointerToObjectAndIntegerType.ql

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,73 @@
1313

1414
import cpp
1515
import codingstandards.c.misra
16+
import codingstandards.cpp.Macro
1617
import codingstandards.cpp.Pointers
1718

18-
from CStyleCast cast, Type typeFrom, Type typeTo
19+
MacroInvocation getAMacroInvocation(CStyleCast cast) { result.getAnExpandedElement() = cast }
20+
21+
Macro getPrimaryMacro(CStyleCast cast) {
22+
exists(MacroInvocation mi |
23+
mi = getAMacroInvocation(cast) and
24+
not exists(MacroInvocation otherMi |
25+
otherMi = getAMacroInvocation(cast) and otherMi.getParentInvocation() = mi
26+
) and
27+
result = mi.getMacro()
28+
)
29+
}
30+
31+
Macro getNonFunctionPrimaryMacro(CStyleCast cast) {
32+
result = getPrimaryMacro(cast) and
33+
not result instanceof FunctionLikeMacro
34+
}
35+
36+
from
37+
Locatable primaryLocation, CStyleCast cast, Type typeFrom, Type typeTo, string message,
38+
string extraMessage, Locatable optionalPlaceholderLocation, string optionalPlaceholderMessage
1939
where
2040
not isExcluded(cast, Pointers1Package::conversionBetweenPointerToObjectAndIntegerTypeQuery()) and
2141
typeFrom = cast.getExpr().getUnderlyingType() and
2242
typeTo = cast.getUnderlyingType() and
23-
[typeFrom, typeTo] instanceof IntegralType and
24-
[typeFrom, typeTo] instanceof PointerToObjectType and
25-
not isNullPointerConstant(cast.getExpr())
26-
select cast, "Cast performed between a pointer to object type and a pointer to an integer type."
43+
(
44+
typeFrom instanceof PointerToObjectType and
45+
typeTo instanceof IntegralType and
46+
message =
47+
"Cast from pointer to object type '" + typeFrom + "' to integer type '" + typeTo + "'" +
48+
extraMessage + "."
49+
or
50+
typeFrom instanceof IntegralType and
51+
typeTo instanceof PointerToObjectType and
52+
message =
53+
"Cast from integer type '" + typeFrom + "' to pointer to object type '" + typeTo + "'" +
54+
extraMessage + "."
55+
) and
56+
not isNullPointerConstant(cast.getExpr()) and
57+
// If this alert is arising through a non-function-like macro expansion, flag the macro instead, to
58+
// help make the alerts more manageable. We only do this for non-function-like macros because they
59+
// cannot be context specific.
60+
if exists(getNonFunctionPrimaryMacro(cast))
61+
then
62+
primaryLocation = getNonFunctionPrimaryMacro(cast) and
63+
extraMessage = "" and
64+
optionalPlaceholderLocation = primaryLocation and
65+
optionalPlaceholderMessage = ""
66+
else (
67+
primaryLocation = cast and
68+
// If the cast is in a macro expansion which is context specific, we still report the original
69+
// location, but also add a link to the most specific macro that contains the cast, to aid
70+
// validation.
71+
if exists(getPrimaryMacro(cast))
72+
then
73+
extraMessage = " from expansion of macro $@" and
74+
exists(Macro m |
75+
m = getPrimaryMacro(cast) and
76+
optionalPlaceholderLocation = m and
77+
optionalPlaceholderMessage = m.getName()
78+
)
79+
else (
80+
extraMessage = "" and
81+
optionalPlaceholderLocation = cast and
82+
optionalPlaceholderMessage = ""
83+
)
84+
)
85+
select primaryLocation, message, optionalPlaceholderLocation, optionalPlaceholderMessage

c/misra/src/rules/RULE-11-6/CastBetweenPointerToVoidAndArithmeticType.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ where
2222
typeTo = cast.getUnderlyingType() and
2323
[typeFrom, typeTo] instanceof ArithmeticType and
2424
[typeFrom, typeTo] instanceof VoidPointerType and
25-
not isNullPointerConstant(cast.getExpr())
25+
not cast.getExpr() instanceof Zero
2626
select cast, "Cast performed between a pointer to void type and an arithmetic type."

c/misra/src/rules/RULE-11-9/MacroNullNotUsedAsIntegerNullPointerConstant.ql

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,25 @@ import codingstandards.cpp.Type
1818
from Zero zero, Expr e, string type
1919
where
2020
not isExcluded(zero, Pointers1Package::macroNullNotUsedAsIntegerNullPointerConstantQuery()) and
21-
// exclude the base-case (NULL macros and void pointer casts)
22-
not isNullPointerConstant(zero) and
21+
// Exclude the base-case (NULL macros and void pointer casts)
22+
// Note: we cannot use the isNullPointerConstant predicate here because it permits
23+
// the use of `0` without casting, which is prohibited here.
24+
not (
25+
zero.findRootCause() instanceof NullMacro
26+
or
27+
// integer constant `0` explicitly cast to void pointer
28+
exists(Conversion c | c = zero.getConversion() |
29+
not c.isImplicit() and
30+
c.getUnderlyingType() instanceof VoidPointerType
31+
)
32+
) and
2333
(
2434
// ?: operator
2535
exists(ConditionalExpr parent |
2636
(
27-
parent.getThen().getAChild*() = zero and parent.getElse().getType() instanceof PointerType
37+
parent.getThen() = zero and parent.getElse().getType() instanceof PointerType
2838
or
29-
parent.getElse().getAChild*() = zero and parent.getThen().getType() instanceof PointerType
39+
parent.getElse() = zero and parent.getThen().getType() instanceof PointerType
3040
) and
3141
// exclude a common conditional pattern used in macros such as 'assert'
3242
not parent.isInMacroExpansion() and

0 commit comments

Comments
 (0)