Skip to content

Commit 0ffa4b1

Browse files
committed
IntegerOverflow: Add package files.
1 parent 23065e4 commit 0ffa4b1

File tree

5 files changed

+246
-6
lines changed

5 files changed

+246
-6
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype IntegerOverflowQuery =
7+
TUnsignedIntegerOperationsWrapAroundQuery() or
8+
TIntegerConversionCausesDataLossQuery() or
9+
TSignedIntegerOverflowQuery() or
10+
TDivOrRemByZeroQuery() or
11+
TUseCorrectIntegerPrecisionsQuery() or
12+
TConstantUnsignedIntegerExpressionsWrapAroundQuery()
13+
14+
predicate isIntegerOverflowQueryMetadata(Query query, string queryId, string ruleId, string category) {
15+
query =
16+
// `Query` instance for the `unsignedIntegerOperationsWrapAround` query
17+
IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery() and
18+
queryId =
19+
// `@id` for the `unsignedIntegerOperationsWrapAround` query
20+
"c/cert/unsigned-integer-operations-wrap-around" and
21+
ruleId = "INT30-C" and
22+
category = "rule"
23+
or
24+
query =
25+
// `Query` instance for the `integerConversionCausesDataLoss` query
26+
IntegerOverflowPackage::integerConversionCausesDataLossQuery() and
27+
queryId =
28+
// `@id` for the `integerConversionCausesDataLoss` query
29+
"c/cert/integer-conversion-causes-data-loss" and
30+
ruleId = "INT31-C" and
31+
category = "rule"
32+
or
33+
query =
34+
// `Query` instance for the `signedIntegerOverflow` query
35+
IntegerOverflowPackage::signedIntegerOverflowQuery() and
36+
queryId =
37+
// `@id` for the `signedIntegerOverflow` query
38+
"c/cert/signed-integer-overflow" and
39+
ruleId = "INT32-C" and
40+
category = "rule"
41+
or
42+
query =
43+
// `Query` instance for the `divOrRemByZero` query
44+
IntegerOverflowPackage::divOrRemByZeroQuery() and
45+
queryId =
46+
// `@id` for the `divOrRemByZero` query
47+
"c/cert/div-or-rem-by-zero" and
48+
ruleId = "INT33-C" and
49+
category = "rule"
50+
or
51+
query =
52+
// `Query` instance for the `useCorrectIntegerPrecisions` query
53+
IntegerOverflowPackage::useCorrectIntegerPrecisionsQuery() and
54+
queryId =
55+
// `@id` for the `useCorrectIntegerPrecisions` query
56+
"c/cert/use-correct-integer-precisions" and
57+
ruleId = "INT35-C" and
58+
category = "rule"
59+
or
60+
query =
61+
// `Query` instance for the `constantUnsignedIntegerExpressionsWrapAround` query
62+
IntegerOverflowPackage::constantUnsignedIntegerExpressionsWrapAroundQuery() and
63+
queryId =
64+
// `@id` for the `constantUnsignedIntegerExpressionsWrapAround` query
65+
"c/misra/constant-unsigned-integer-expressions-wrap-around" and
66+
ruleId = "RULE-12-4" and
67+
category = "advisory"
68+
}
69+
70+
module IntegerOverflowPackage {
71+
Query unsignedIntegerOperationsWrapAroundQuery() {
72+
//autogenerate `Query` type
73+
result =
74+
// `Query` type for `unsignedIntegerOperationsWrapAround` query
75+
TQueryC(TIntegerOverflowPackageQuery(TUnsignedIntegerOperationsWrapAroundQuery()))
76+
}
77+
78+
Query integerConversionCausesDataLossQuery() {
79+
//autogenerate `Query` type
80+
result =
81+
// `Query` type for `integerConversionCausesDataLoss` query
82+
TQueryC(TIntegerOverflowPackageQuery(TIntegerConversionCausesDataLossQuery()))
83+
}
84+
85+
Query signedIntegerOverflowQuery() {
86+
//autogenerate `Query` type
87+
result =
88+
// `Query` type for `signedIntegerOverflow` query
89+
TQueryC(TIntegerOverflowPackageQuery(TSignedIntegerOverflowQuery()))
90+
}
91+
92+
Query divOrRemByZeroQuery() {
93+
//autogenerate `Query` type
94+
result =
95+
// `Query` type for `divOrRemByZero` query
96+
TQueryC(TIntegerOverflowPackageQuery(TDivOrRemByZeroQuery()))
97+
}
98+
99+
Query useCorrectIntegerPrecisionsQuery() {
100+
//autogenerate `Query` type
101+
result =
102+
// `Query` type for `useCorrectIntegerPrecisions` query
103+
TQueryC(TIntegerOverflowPackageQuery(TUseCorrectIntegerPrecisionsQuery()))
104+
}
105+
106+
Query constantUnsignedIntegerExpressionsWrapAroundQuery() {
107+
//autogenerate `Query` type
108+
result =
109+
// `Query` type for `constantUnsignedIntegerExpressionsWrapAround` query
110+
TQueryC(TIntegerOverflowPackageQuery(TConstantUnsignedIntegerExpressionsWrapAroundQuery()))
111+
}
112+
}

cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import IO1
3030
import IO2
3131
import IO3
3232
import IO4
33+
import IntegerOverflow
3334
import InvalidMemory1
3435
import Language1
3536
import Language2
@@ -81,6 +82,7 @@ newtype TCQuery =
8182
TIO2PackageQuery(IO2Query q) or
8283
TIO3PackageQuery(IO3Query q) or
8384
TIO4PackageQuery(IO4Query q) or
85+
TIntegerOverflowPackageQuery(IntegerOverflowQuery q) or
8486
TInvalidMemory1PackageQuery(InvalidMemory1Query q) or
8587
TLanguage1PackageQuery(Language1Query q) or
8688
TLanguage2PackageQuery(Language2Query q) or
@@ -132,6 +134,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
132134
isIO2QueryMetadata(query, queryId, ruleId, category) or
133135
isIO3QueryMetadata(query, queryId, ruleId, category) or
134136
isIO4QueryMetadata(query, queryId, ruleId, category) or
137+
isIntegerOverflowQueryMetadata(query, queryId, ruleId, category) or
135138
isInvalidMemory1QueryMetadata(query, queryId, ruleId, category) or
136139
isLanguage1QueryMetadata(query, queryId, ruleId, category) or
137140
isLanguage2QueryMetadata(query, queryId, ruleId, category) or

rule_packages/c/IntegerOverflow.json

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"CERT-C": {
3+
"INT30-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "Unsigned integer expressions do not strictly overflow, but instead wrap around in a modular way. If the size of the type is not sufficient, this can happen unexpectedly.",
10+
"kind": "problem",
11+
"name": "Ensure that unsigned integer operations do not wrap",
12+
"precision": "high",
13+
"severity": "error",
14+
"short_name": "UnsignedIntegerOperationsWrapAround",
15+
"tags": [
16+
"correctness",
17+
"security"
18+
]
19+
}
20+
],
21+
"title": "Ensure that unsigned integer operations do not wrap"
22+
},
23+
"INT31-C": {
24+
"properties": {
25+
"obligation": "rule"
26+
},
27+
"queries": [
28+
{
29+
"description": "",
30+
"kind": "problem",
31+
"name": "Ensure that integer conversions do not result in lost or misinterpreted data",
32+
"precision": "high",
33+
"severity": "error",
34+
"short_name": "IntegerConversionCausesDataLoss",
35+
"tags": [
36+
"correctness"
37+
]
38+
}
39+
],
40+
"title": "Ensure that integer conversions do not result in lost or misinterpreted data"
41+
},
42+
"INT32-C": {
43+
"properties": {
44+
"obligation": "rule"
45+
},
46+
"queries": [
47+
{
48+
"description": "",
49+
"kind": "problem",
50+
"name": "Ensure that operations on signed integers do not result in overflow",
51+
"precision": "high",
52+
"severity": "error",
53+
"short_name": "SignedIntegerOverflow",
54+
"tags": [
55+
"correctness",
56+
"security"
57+
]
58+
}
59+
],
60+
"title": "Ensure that operations on signed integers do not result in overflow"
61+
},
62+
"INT33-C": {
63+
"properties": {
64+
"obligation": "rule"
65+
},
66+
"queries": [
67+
{
68+
"description": "Dividing or taking the remainder by zero is undefined behavior.",
69+
"kind": "problem",
70+
"name": "Ensure that division and remainder operations do not result in divide-by-zero errors",
71+
"precision": "high",
72+
"severity": "error",
73+
"short_name": "DivOrRemByZero",
74+
"tags": [
75+
"correctness"
76+
]
77+
}
78+
],
79+
"title": "Ensure that division and remainder operations do not result in divide-by-zero errors"
80+
},
81+
"INT35-C": {
82+
"properties": {
83+
"obligation": "rule"
84+
},
85+
"queries": [
86+
{
87+
"description": "",
88+
"kind": "problem",
89+
"name": "Use correct integer precisions",
90+
"precision": "high",
91+
"severity": "error",
92+
"short_name": "UseCorrectIntegerPrecisions",
93+
"tags": [
94+
"correctness"
95+
]
96+
}
97+
],
98+
"title": "Use correct integer precisions"
99+
}
100+
},
101+
"MISRA-C-2012": {
102+
"RULE-12-4": {
103+
"properties": {
104+
"obligation": "advisory"
105+
},
106+
"queries": [
107+
{
108+
"description": "Unsigned integer expressions do not strictly overflow, but instead wrap around in a modular way. Any constant unsigned integer expressions that in effect \"overflow\" will not be detected by the compiler. Although there may be good reasons at run-time to rely on the modular arithmetic provided by unsigned integer types, the reasons for using it at compile-time to evaluate a constant expression are less obvious. Any instance of an unsigned integer constant expression wrapping around is therefore likely to indicate a programming error.",
109+
"kind": "problem",
110+
"name": "Evaluation of constant expressions should not lead to unsigned integer wrap-around",
111+
"precision": "very-high",
112+
"severity": "error",
113+
"short_name": "ConstantUnsignedIntegerExpressionsWrapAround",
114+
"shared_implementation_short_name": "ConstantUnsignedIntegerExpressionsWrapAround",
115+
"tags": [
116+
"correctness",
117+
"security"
118+
]
119+
}
120+
],
121+
"title": "Evaluation of constant expressions should not lead to unsigned integer wrap-around"
122+
}
123+
}
124+
}

rule_packages/cpp/Expressions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
"precision": "very-high",
250250
"severity": "error",
251251
"short_name": "ConstantUnsignedIntegerExpressionsWrapAround",
252+
"shared_implementation_short_name": "ConstantUnsignedIntegerExpressionsWrapAround",
252253
"tags": [
253254
"correctness",
254255
"security"

rules.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,12 @@ c,CERT-C,FLP32-C,Yes,Rule,,,Prevent or detect domain and range errors in math fu
548548
c,CERT-C,FLP34-C,Yes,Rule,,,Ensure that floating-point conversions are within range of the new type,,Types,Medium,
549549
c,CERT-C,FLP36-C,Yes,Rule,,,Preserve precision when converting integral values to floating-point type,,Types,Medium,
550550
c,CERT-C,FLP37-C,Yes,Rule,,,Do not use object representations to compare floating-point values,,Types,Medium,
551-
c,CERT-C,INT30-C,Yes,Rule,,,Ensure that unsigned integer operations do not wrap,A4-7-1,Types,Hard,
552-
c,CERT-C,INT31-C,Yes,Rule,,,Ensure that integer conversions do not result in lost or misinterpreted data,A4-7-1,Types,Hard,
553-
c,CERT-C,INT32-C,Yes,Rule,,,Ensure that operations on signed integers do not result in overflow,A4-7-1,Types,Hard,
554-
c,CERT-C,INT33-C,Yes,Rule,,,Ensure that division and remainder operations do not result in divide-by-zero errors,,Types,Hard,
551+
c,CERT-C,INT30-C,Yes,Rule,,,Ensure that unsigned integer operations do not wrap,A4-7-1,IntegerOverflow,Hard,
552+
c,CERT-C,INT31-C,Yes,Rule,,,Ensure that integer conversions do not result in lost or misinterpreted data,A4-7-1,IntegerOverflow,Hard,
553+
c,CERT-C,INT32-C,Yes,Rule,,,Ensure that operations on signed integers do not result in overflow,A4-7-1,IntegerOverflow,Hard,
554+
c,CERT-C,INT33-C,Yes,Rule,,,Ensure that division and remainder operations do not result in divide-by-zero errors,,IntegerOverflow,Hard,
555555
c,CERT-C,INT34-C,Yes,Rule,,,Do not shift an expression by a negative number of bits or by greater than or equal to the number of bits that exist in the operand,M5-8-1,Types,Import,
556-
c,CERT-C,INT35-C,Yes,Rule,,,Use correct integer precisions,,Types,Hard,
556+
c,CERT-C,INT35-C,Yes,Rule,,,Use correct integer precisions,,IntegerOverflow,Hard,
557557
c,CERT-C,INT36-C,Yes,Rule,,,Converting a pointer to integer or integer to pointer,M5-2-9,Types,Easy,
558558
c,CERT-C,MEM30-C,Yes,Rule,,,Do not access freed memory,MEM50-CPP,InvalidMemory1,Import,
559559
c,CERT-C,MEM31-C,Yes,Rule,,,Free dynamically allocated memory when no longer needed,,Memory2,Very Hard,
@@ -685,7 +685,7 @@ c,MISRA-C-2012,RULE-11-9,Yes,Required,,,The macro NULL shall be the only permitt
685685
c,MISRA-C-2012,RULE-12-1,Yes,Advisory,,,The precedence of operators within expressions should be made explicit,,SideEffects1,Medium,
686686
c,MISRA-C-2012,RULE-12-2,Yes,Required,,,The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand,,Contracts,Medium,
687687
c,MISRA-C-2012,RULE-12-3,Yes,Advisory,,,The comma operator should not be used,M5-18-1,Banned,Import,
688-
c,MISRA-C-2012,RULE-12-4,Yes,Advisory,,,Evaluation of constant expressions should not lead to unsigned integer wrap-around,INT30-C,Types,Easy,
688+
c,MISRA-C-2012,RULE-12-4,Yes,Advisory,,,Evaluation of constant expressions should not lead to unsigned integer wrap-around,INT30-C,IntegerOverflow,Easy,
689689
c,MISRA-C-2012,RULE-12-5,Yes,Mandatory,,,The sizeof operator shall not have an operand which is a function parameter declared as �array of type�,,Types,Medium,
690690
c,MISRA-C-2012,RULE-13-1,Yes,Required,,,Initializer lists shall not contain persistent side effects,,SideEffects1,Medium,
691691
c,MISRA-C-2012,RULE-13-2,Yes,Required,,,The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders,PRE31-C,SideEffects,Medium,

0 commit comments

Comments
 (0)