Skip to content

Commit 1844339

Browse files
committed
Add BannedAPIs package details
1 parent 0eb6feb commit 1844339

File tree

3 files changed

+350
-0
lines changed

3 files changed

+350
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype BannedAPIsQuery =
7+
TAvoidProgramTerminatingFunctionsQuery() or
8+
TNoVariadicFunctionMacrosQuery() or
9+
TNoCsetjmpHeaderQuery() or
10+
TUnsafeStringHandlingFunctionsQuery() or
11+
TBannedSystemFunctionQuery() or
12+
TUseSmartPtrFactoryFunctionsQuery() or
13+
TCharacterHandlingFunctionRestrictionsQuery() or
14+
TNoMemoryFunctionsFromCStringQuery() or
15+
TLocaleGlobalFunctionNotAllowedQuery()
16+
17+
predicate isBannedAPIsQueryMetadata(Query query, string queryId, string ruleId, string category) {
18+
query =
19+
// `Query` instance for the `avoidProgramTerminatingFunctions` query
20+
BannedAPIsPackage::avoidProgramTerminatingFunctionsQuery() and
21+
queryId =
22+
// `@id` for the `avoidProgramTerminatingFunctions` query
23+
"cpp/misra/avoid-program-terminating-functions" and
24+
ruleId = "RULE-18-5-2" and
25+
category = "advisory"
26+
or
27+
query =
28+
// `Query` instance for the `noVariadicFunctionMacros` query
29+
BannedAPIsPackage::noVariadicFunctionMacrosQuery() and
30+
queryId =
31+
// `@id` for the `noVariadicFunctionMacros` query
32+
"cpp/misra/no-variadic-function-macros" and
33+
ruleId = "RULE-21-10-1" and
34+
category = "required"
35+
or
36+
query =
37+
// `Query` instance for the `noCsetjmpHeader` query
38+
BannedAPIsPackage::noCsetjmpHeaderQuery() and
39+
queryId =
40+
// `@id` for the `noCsetjmpHeader` query
41+
"cpp/misra/no-csetjmp-header" and
42+
ruleId = "RULE-21-10-2" and
43+
category = "required"
44+
or
45+
query =
46+
// `Query` instance for the `unsafeStringHandlingFunctions` query
47+
BannedAPIsPackage::unsafeStringHandlingFunctionsQuery() and
48+
queryId =
49+
// `@id` for the `unsafeStringHandlingFunctions` query
50+
"cpp/misra/unsafe-string-handling-functions" and
51+
ruleId = "RULE-21-2-2" and
52+
category = "required"
53+
or
54+
query =
55+
// `Query` instance for the `bannedSystemFunction` query
56+
BannedAPIsPackage::bannedSystemFunctionQuery() and
57+
queryId =
58+
// `@id` for the `bannedSystemFunction` query
59+
"cpp/misra/banned-system-function" and
60+
ruleId = "RULE-21-2-3" and
61+
category = "required"
62+
or
63+
query =
64+
// `Query` instance for the `useSmartPtrFactoryFunctions` query
65+
BannedAPIsPackage::useSmartPtrFactoryFunctionsQuery() and
66+
queryId =
67+
// `@id` for the `useSmartPtrFactoryFunctions` query
68+
"cpp/misra/use-smart-ptr-factory-functions" and
69+
ruleId = "RULE-23-11-1" and
70+
category = "advisory"
71+
or
72+
query =
73+
// `Query` instance for the `characterHandlingFunctionRestrictions` query
74+
BannedAPIsPackage::characterHandlingFunctionRestrictionsQuery() and
75+
queryId =
76+
// `@id` for the `characterHandlingFunctionRestrictions` query
77+
"cpp/misra/character-handling-function-restrictions" and
78+
ruleId = "RULE-24-5-1" and
79+
category = "required"
80+
or
81+
query =
82+
// `Query` instance for the `noMemoryFunctionsFromCString` query
83+
BannedAPIsPackage::noMemoryFunctionsFromCStringQuery() and
84+
queryId =
85+
// `@id` for the `noMemoryFunctionsFromCString` query
86+
"cpp/misra/no-memory-functions-from-c-string" and
87+
ruleId = "RULE-24-5-2" and
88+
category = "required"
89+
or
90+
query =
91+
// `Query` instance for the `localeGlobalFunctionNotAllowed` query
92+
BannedAPIsPackage::localeGlobalFunctionNotAllowedQuery() and
93+
queryId =
94+
// `@id` for the `localeGlobalFunctionNotAllowed` query
95+
"cpp/misra/locale-global-function-not-allowed" and
96+
ruleId = "RULE-25-5-1" and
97+
category = "required"
98+
}
99+
100+
module BannedAPIsPackage {
101+
Query avoidProgramTerminatingFunctionsQuery() {
102+
//autogenerate `Query` type
103+
result =
104+
// `Query` type for `avoidProgramTerminatingFunctions` query
105+
TQueryCPP(TBannedAPIsPackageQuery(TAvoidProgramTerminatingFunctionsQuery()))
106+
}
107+
108+
Query noVariadicFunctionMacrosQuery() {
109+
//autogenerate `Query` type
110+
result =
111+
// `Query` type for `noVariadicFunctionMacros` query
112+
TQueryCPP(TBannedAPIsPackageQuery(TNoVariadicFunctionMacrosQuery()))
113+
}
114+
115+
Query noCsetjmpHeaderQuery() {
116+
//autogenerate `Query` type
117+
result =
118+
// `Query` type for `noCsetjmpHeader` query
119+
TQueryCPP(TBannedAPIsPackageQuery(TNoCsetjmpHeaderQuery()))
120+
}
121+
122+
Query unsafeStringHandlingFunctionsQuery() {
123+
//autogenerate `Query` type
124+
result =
125+
// `Query` type for `unsafeStringHandlingFunctions` query
126+
TQueryCPP(TBannedAPIsPackageQuery(TUnsafeStringHandlingFunctionsQuery()))
127+
}
128+
129+
Query bannedSystemFunctionQuery() {
130+
//autogenerate `Query` type
131+
result =
132+
// `Query` type for `bannedSystemFunction` query
133+
TQueryCPP(TBannedAPIsPackageQuery(TBannedSystemFunctionQuery()))
134+
}
135+
136+
Query useSmartPtrFactoryFunctionsQuery() {
137+
//autogenerate `Query` type
138+
result =
139+
// `Query` type for `useSmartPtrFactoryFunctions` query
140+
TQueryCPP(TBannedAPIsPackageQuery(TUseSmartPtrFactoryFunctionsQuery()))
141+
}
142+
143+
Query characterHandlingFunctionRestrictionsQuery() {
144+
//autogenerate `Query` type
145+
result =
146+
// `Query` type for `characterHandlingFunctionRestrictions` query
147+
TQueryCPP(TBannedAPIsPackageQuery(TCharacterHandlingFunctionRestrictionsQuery()))
148+
}
149+
150+
Query noMemoryFunctionsFromCStringQuery() {
151+
//autogenerate `Query` type
152+
result =
153+
// `Query` type for `noMemoryFunctionsFromCString` query
154+
TQueryCPP(TBannedAPIsPackageQuery(TNoMemoryFunctionsFromCStringQuery()))
155+
}
156+
157+
Query localeGlobalFunctionNotAllowedQuery() {
158+
//autogenerate `Query` type
159+
result =
160+
// `Query` type for `localeGlobalFunctionNotAllowed` query
161+
TQueryCPP(TBannedAPIsPackageQuery(TLocaleGlobalFunctionNotAllowedQuery()))
162+
}
163+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cpp
33
import codingstandards.cpp.exclusions.RuleMetadata
44
//** Import packages for this language **/
55
import Allocations
6+
import BannedAPIs
67
import BannedFunctions
78
import BannedLibraries
89
import BannedSyntax
@@ -58,6 +59,7 @@ import VirtualFunctions
5859
/** The TQuery type representing this language * */
5960
newtype TCPPQuery =
6061
TAllocationsPackageQuery(AllocationsQuery q) or
62+
TBannedAPIsPackageQuery(BannedAPIsQuery q) or
6163
TBannedFunctionsPackageQuery(BannedFunctionsQuery q) or
6264
TBannedLibrariesPackageQuery(BannedLibrariesQuery q) or
6365
TBannedSyntaxPackageQuery(BannedSyntaxQuery q) or
@@ -113,6 +115,7 @@ newtype TCPPQuery =
113115
/** The metadata predicate * */
114116
predicate isQueryMetadata(Query query, string queryId, string ruleId, string category) {
115117
isAllocationsQueryMetadata(query, queryId, ruleId, category) or
118+
isBannedAPIsQueryMetadata(query, queryId, ruleId, category) or
116119
isBannedFunctionsQueryMetadata(query, queryId, ruleId, category) or
117120
isBannedLibrariesQueryMetadata(query, queryId, ruleId, category) or
118121
isBannedSyntaxQueryMetadata(query, queryId, ruleId, category) or

rule_packages/cpp/BannedAPIs.json

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
{
2+
"MISRA-C++-2023": {
3+
"RULE-18-5-2": {
4+
"properties": {
5+
"enforcement": "decidable",
6+
"obligation": "advisory"
7+
},
8+
"queries": [
9+
{
10+
"description": "Using program-terminating functions like abort, exit, _Exit, quick_exit or terminate causes the stack to not be unwound and object destructors to not be called, potentially leaving the environment in an undesirable state.",
11+
"kind": "problem",
12+
"name": "Program-terminating functions should not be used",
13+
"precision": "very-high",
14+
"severity": "error",
15+
"short_name": "AvoidProgramTerminatingFunctions",
16+
"tags": [
17+
"scope/single-translation-unit"
18+
]
19+
}
20+
],
21+
"title": "Program-terminating functions should not be used"
22+
},
23+
"RULE-21-10-1": {
24+
"properties": {
25+
"enforcement": "decidable",
26+
"obligation": "required"
27+
},
28+
"queries": [
29+
{
30+
"description": "Using <cstdarg> features like va_list, va_arg, va_start, va_end and va_copy bypasses compiler type checking and leads to undefined behavior when used incorrectly.",
31+
"kind": "problem",
32+
"name": "The features of <cstdarg> shall not be used",
33+
"precision": "very-high",
34+
"severity": "error",
35+
"short_name": "NoVariadicFunctionMacros",
36+
"tags": [
37+
"scope/single-translation-unit"
38+
]
39+
}
40+
],
41+
"title": "The features of <cstdarg> shall not be used"
42+
},
43+
"RULE-21-10-2": {
44+
"properties": {
45+
"enforcement": "decidable",
46+
"obligation": "required"
47+
},
48+
"queries": [
49+
{
50+
"description": "Using facilities from the <csetjmp> header causes undefined behavior by bypassing normal function return mechanisms and may result in non-trivial object destruction being omitted.",
51+
"kind": "problem",
52+
"name": "The standard header file <csetjmp> shall not be used",
53+
"precision": "very-high",
54+
"severity": "error",
55+
"short_name": "NoCsetjmpHeader",
56+
"tags": [
57+
"scope/single-translation-unit"
58+
]
59+
}
60+
],
61+
"title": "The standard header file <csetjmp> shall not be used"
62+
},
63+
"RULE-21-2-2": {
64+
"properties": {
65+
"enforcement": "decidable",
66+
"obligation": "required"
67+
},
68+
"queries": [
69+
{
70+
"description": "Using string handling functions from <cstring>, <cstdlib>, <cwchar> and <cinttypes> headers may result in buffer overflows or unreliable error detection through errno.",
71+
"kind": "problem",
72+
"name": "The string handling functions from <cstring>, <cstdlib>, <cwchar> and <cinttypes> shall not be used",
73+
"precision": "very-high",
74+
"severity": "error",
75+
"short_name": "UnsafeStringHandlingFunctions",
76+
"tags": [
77+
"scope/single-translation-unit"
78+
]
79+
}
80+
],
81+
"title": "The string handling functions from <cstring>, <cstdlib>, <cwchar> and <cinttypes> shall not be used"
82+
},
83+
"RULE-21-2-3": {
84+
"properties": {
85+
"enforcement": "decidable",
86+
"obligation": "required"
87+
},
88+
"queries": [
89+
{
90+
"description": "Using the system() function from cstdlib or stdlib.h causes undefined behavior and potential security vulnerabilities.",
91+
"kind": "problem",
92+
"name": "The library function system from <cstdlib> shall not be used",
93+
"precision": "very-high",
94+
"severity": "error",
95+
"short_name": "BannedSystemFunction",
96+
"tags": [
97+
"scope/single-translation-unit"
98+
]
99+
}
100+
],
101+
"title": "The library function system from <cstdlib> shall not be used"
102+
},
103+
"RULE-23-11-1": {
104+
"properties": {
105+
"enforcement": "decidable",
106+
"obligation": "advisory"
107+
},
108+
"queries": [
109+
{
110+
"description": "Using raw pointer constructors of std::shared_ptr and std::unique_ptr instead of make_shared/make_unique can lead to memory leaks if exceptions occur during construction.",
111+
"kind": "problem",
112+
"name": "The raw pointer constructors of std::shared_ptr and std::unique_ptr should not be used",
113+
"precision": "very-high",
114+
"severity": "error",
115+
"short_name": "UseSmartPtrFactoryFunctions",
116+
"tags": [
117+
"scope/single-translation-unit"
118+
]
119+
}
120+
],
121+
"title": "The raw pointer constructors of std::shared_ptr and std::unique_ptr should not be used"
122+
},
123+
"RULE-24-5-1": {
124+
"properties": {
125+
"enforcement": "decidable",
126+
"obligation": "required"
127+
},
128+
"queries": [
129+
{
130+
"description": "Using character classification and case mapping functions from <cctype> and <cwctype> causes undefined behavior when arguments are not representable as unsigned char or not equal to EOF.",
131+
"kind": "problem",
132+
"name": "The character handling functions from <cctype> and <cwctype> shall not be used",
133+
"precision": "very-high",
134+
"severity": "error",
135+
"short_name": "CharacterHandlingFunctionRestrictions",
136+
"tags": [
137+
"scope/single-translation-unit"
138+
]
139+
}
140+
],
141+
"title": "The character handling functions from <cctype> and <cwctype> shall not be used"
142+
},
143+
"RULE-24-5-2": {
144+
"properties": {
145+
"enforcement": "decidable",
146+
"obligation": "required"
147+
},
148+
"queries": [
149+
{
150+
"description": "Using memcpy, memmove or memcmp from <cstring> can result in undefined behavior due to overlapping memory, non-trivially copyable objects, or unequal comparison of logically equal objects.",
151+
"kind": "problem",
152+
"name": "The C++ Standard Library functions memcpy, memmove and memcmp from <cstring> shall not be used",
153+
"precision": "very-high",
154+
"severity": "error",
155+
"short_name": "NoMemoryFunctionsFromCString",
156+
"tags": [
157+
"scope/single-translation-unit"
158+
]
159+
}
160+
],
161+
"title": "The C++ Standard Library functions memcpy, memmove and memcmp from <cstring> shall not be used"
162+
},
163+
"RULE-25-5-1": {
164+
"properties": {
165+
"enforcement": "decidable",
166+
"obligation": "required"
167+
},
168+
"queries": [
169+
{
170+
"description": "Calling setlocale or std::locale::global functions can introduce data races with functions that use the locale, leading to undefined behavior.",
171+
"kind": "problem",
172+
"name": "The setlocale and std::locale::global functions shall not be called",
173+
"precision": "very-high",
174+
"severity": "error",
175+
"short_name": "LocaleGlobalFunctionNotAllowed",
176+
"tags": [
177+
"scope/single-translation-unit"
178+
]
179+
}
180+
],
181+
"title": "The setlocale and std::locale::global functions shall not be called"
182+
}
183+
}
184+
}

0 commit comments

Comments
 (0)