Skip to content

Commit 8647dd4

Browse files
committed
Add rule category to rule meta data
The category information enables evaluation time computation of the effective category of a rule. The effective category is determined by the rule's category and a possible recategorization through a Guideline Recategorization Plan. The effective category will be used to determine how to handle a deviation applied to a query implementing the rule.
1 parent 0291b4c commit 8647dd4

File tree

92 files changed

+1636
-903
lines changed

Some content is hidden

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

92 files changed

+1636
-903
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ newtype TQuery =
88

99
class Query extends TQuery {
1010
string getQueryId() {
11-
CPPRuleMetadata::isQueryMetadata(this, result, _) or
12-
CRuleMetadata::isQueryMetadata(this, result, _)
11+
CPPRuleMetadata::isQueryMetadata(this, result, _, _) or
12+
CRuleMetadata::isQueryMetadata(this, result, _, _)
1313
}
1414

1515
string getRuleId() {
16-
CPPRuleMetadata::isQueryMetadata(this, _, result) or
17-
CRuleMetadata::isQueryMetadata(this, _, result)
16+
CPPRuleMetadata::isQueryMetadata(this, _, result, _) or
17+
CRuleMetadata::isQueryMetadata(this, _, result, _)
18+
}
19+
20+
string getCategory() {
21+
CPPRuleMetadata::isQueryMetadata(this, _, _, result) or
22+
CRuleMetadata::isQueryMetadata(this, _, _, result)
1823
}
1924

2025
string toString() { result = getQueryId() }

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

+39-20
Original file line numberDiff line numberDiff line change
@@ -24,158 +24,177 @@ newtype BannedQuery =
2424
TOctalConstantsUsedQuery() or
2525
TRestrictTypeQualifierUsedQuery()
2626

27-
predicate isBannedQueryMetadata(Query query, string queryId, string ruleId) {
27+
predicate isBannedQueryMetadata(Query query, string queryId, string ruleId, string category) {
2828
query =
2929
// `Query` instance for the `doNotCallSystem` query
3030
BannedPackage::doNotCallSystemQuery() and
3131
queryId =
3232
// `@id` for the `doNotCallSystem` query
3333
"c/cert/do-not-call-system" and
34-
ruleId = "ENV33-C"
34+
ruleId = "ENV33-C" and
35+
category = "rule"
3536
or
3637
query =
3738
// `Query` instance for the `commaOperatorShouldNotBeUsed` query
3839
BannedPackage::commaOperatorShouldNotBeUsedQuery() and
3940
queryId =
4041
// `@id` for the `commaOperatorShouldNotBeUsed` query
4142
"c/misra/comma-operator-should-not-be-used" and
42-
ruleId = "RULE-12-3"
43+
ruleId = "RULE-12-3" and
44+
category = "advisory"
4345
or
4446
query =
4547
// `Query` instance for the `featuresOfStdarghUsed` query
4648
BannedPackage::featuresOfStdarghUsedQuery() and
4749
queryId =
4850
// `@id` for the `featuresOfStdarghUsed` query
4951
"c/misra/features-of-stdargh-used" and
50-
ruleId = "RULE-17-1"
52+
ruleId = "RULE-17-1" and
53+
category = "required"
5154
or
5255
query =
5356
// `Query` instance for the `unionKeywordShouldNotBeUsed` query
5457
BannedPackage::unionKeywordShouldNotBeUsedQuery() and
5558
queryId =
5659
// `@id` for the `unionKeywordShouldNotBeUsed` query
5760
"c/misra/union-keyword-should-not-be-used" and
58-
ruleId = "RULE-19-2"
61+
ruleId = "RULE-19-2" and
62+
category = "advisory"
5963
or
6064
query =
6165
// `Query` instance for the `standardLibraryTimeAndDateFunctionsUsed` query
6266
BannedPackage::standardLibraryTimeAndDateFunctionsUsedQuery() and
6367
queryId =
6468
// `@id` for the `standardLibraryTimeAndDateFunctionsUsed` query
6569
"c/misra/standard-library-time-and-date-functions-used" and
66-
ruleId = "RULE-21-10"
70+
ruleId = "RULE-21-10" and
71+
category = "required"
6772
or
6873
query =
6974
// `Query` instance for the `standardHeaderFileTgmathhUsed` query
7075
BannedPackage::standardHeaderFileTgmathhUsedQuery() and
7176
queryId =
7277
// `@id` for the `standardHeaderFileTgmathhUsed` query
7378
"c/misra/standard-header-file-tgmathh-used" and
74-
ruleId = "RULE-21-11"
79+
ruleId = "RULE-21-11" and
80+
category = "required"
7581
or
7682
query =
7783
// `Query` instance for the `exceptionHandlingFeaturesOfFenvhUsed` query
7884
BannedPackage::exceptionHandlingFeaturesOfFenvhUsedQuery() and
7985
queryId =
8086
// `@id` for the `exceptionHandlingFeaturesOfFenvhUsed` query
8187
"c/misra/exception-handling-features-of-fenvh-used" and
82-
ruleId = "RULE-21-12"
88+
ruleId = "RULE-21-12" and
89+
category = "advisory"
8390
or
8491
query =
8592
// `Query` instance for the `systemOfStdlibhUsed` query
8693
BannedPackage::systemOfStdlibhUsedQuery() and
8794
queryId =
8895
// `@id` for the `systemOfStdlibhUsed` query
8996
"c/misra/system-of-stdlibh-used" and
90-
ruleId = "RULE-21-21"
97+
ruleId = "RULE-21-21" and
98+
category = "required"
9199
or
92100
query =
93101
// `Query` instance for the `memoryAllocDeallocFunctionsOfStdlibhUsed` query
94102
BannedPackage::memoryAllocDeallocFunctionsOfStdlibhUsedQuery() and
95103
queryId =
96104
// `@id` for the `memoryAllocDeallocFunctionsOfStdlibhUsed` query
97105
"c/misra/memory-alloc-dealloc-functions-of-stdlibh-used" and
98-
ruleId = "RULE-21-3"
106+
ruleId = "RULE-21-3" and
107+
category = "required"
99108
or
100109
query =
101110
// `Query` instance for the `standardHeaderFileUsedSetjmph` query
102111
BannedPackage::standardHeaderFileUsedSetjmphQuery() and
103112
queryId =
104113
// `@id` for the `standardHeaderFileUsedSetjmph` query
105114
"c/misra/standard-header-file-used-setjmph" and
106-
ruleId = "RULE-21-4"
115+
ruleId = "RULE-21-4" and
116+
category = "required"
107117
or
108118
query =
109119
// `Query` instance for the `standardHeaderFileUsedSignalh` query
110120
BannedPackage::standardHeaderFileUsedSignalhQuery() and
111121
queryId =
112122
// `@id` for the `standardHeaderFileUsedSignalh` query
113123
"c/misra/standard-header-file-used-signalh" and
114-
ruleId = "RULE-21-5"
124+
ruleId = "RULE-21-5" and
125+
category = "required"
115126
or
116127
query =
117128
// `Query` instance for the `standardLibraryInputoutputFunctionsUsed` query
118129
BannedPackage::standardLibraryInputoutputFunctionsUsedQuery() and
119130
queryId =
120131
// `@id` for the `standardLibraryInputoutputFunctionsUsed` query
121132
"c/misra/standard-library-inputoutput-functions-used" and
122-
ruleId = "RULE-21-6"
133+
ruleId = "RULE-21-6" and
134+
category = "required"
123135
or
124136
query =
125137
// `Query` instance for the `atofAtoiAtolAndAtollOfStdlibhUsed` query
126138
BannedPackage::atofAtoiAtolAndAtollOfStdlibhUsedQuery() and
127139
queryId =
128140
// `@id` for the `atofAtoiAtolAndAtollOfStdlibhUsed` query
129141
"c/misra/atof-atoi-atol-and-atoll-of-stdlibh-used" and
130-
ruleId = "RULE-21-7"
142+
ruleId = "RULE-21-7" and
143+
category = "required"
131144
or
132145
query =
133146
// `Query` instance for the `terminationFunctionsOfStdlibhUsed` query
134147
BannedPackage::terminationFunctionsOfStdlibhUsedQuery() and
135148
queryId =
136149
// `@id` for the `terminationFunctionsOfStdlibhUsed` query
137150
"c/misra/termination-functions-of-stdlibh-used" and
138-
ruleId = "RULE-21-8"
151+
ruleId = "RULE-21-8" and
152+
category = "required"
139153
or
140154
query =
141155
// `Query` instance for the `terminationMacrosOfStdlibhUsed` query
142156
BannedPackage::terminationMacrosOfStdlibhUsedQuery() and
143157
queryId =
144158
// `@id` for the `terminationMacrosOfStdlibhUsed` query
145159
"c/misra/termination-macros-of-stdlibh-used" and
146-
ruleId = "RULE-21-8"
160+
ruleId = "RULE-21-8" and
161+
category = "required"
147162
or
148163
query =
149164
// `Query` instance for the `bsearchAndQsortOfStdlibhUsed` query
150165
BannedPackage::bsearchAndQsortOfStdlibhUsedQuery() and
151166
queryId =
152167
// `@id` for the `bsearchAndQsortOfStdlibhUsed` query
153168
"c/misra/bsearch-and-qsort-of-stdlibh-used" and
154-
ruleId = "RULE-21-9"
169+
ruleId = "RULE-21-9" and
170+
category = "required"
155171
or
156172
query =
157173
// `Query` instance for the `stdLibDynamicMemoryAllocationUsed` query
158174
BannedPackage::stdLibDynamicMemoryAllocationUsedQuery() and
159175
queryId =
160176
// `@id` for the `stdLibDynamicMemoryAllocationUsed` query
161177
"c/misra/std-lib-dynamic-memory-allocation-used" and
162-
ruleId = "DIR-4-12"
178+
ruleId = "DIR-4-12" and
179+
category = "required"
163180
or
164181
query =
165182
// `Query` instance for the `octalConstantsUsed` query
166183
BannedPackage::octalConstantsUsedQuery() and
167184
queryId =
168185
// `@id` for the `octalConstantsUsed` query
169186
"c/misra/octal-constants-used" and
170-
ruleId = "RULE-7-1"
187+
ruleId = "RULE-7-1" and
188+
category = "required"
171189
or
172190
query =
173191
// `Query` instance for the `restrictTypeQualifierUsed` query
174192
BannedPackage::restrictTypeQualifierUsedQuery() and
175193
queryId =
176194
// `@id` for the `restrictTypeQualifierUsed` query
177195
"c/misra/restrict-type-qualifier-used" and
178-
ruleId = "RULE-8-14"
196+
ruleId = "RULE-8-14" and
197+
category = "required"
179198
}
180199

181200
module BannedPackage {

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,33 @@ newtype Concurrency1Query =
88
TRaceConditionsWhenUsingLibraryFunctionsQuery() or
99
TDoNotCallSignalInMultithreadedProgramQuery()
1010

11-
predicate isConcurrency1QueryMetadata(Query query, string queryId, string ruleId) {
11+
predicate isConcurrency1QueryMetadata(Query query, string queryId, string ruleId, string category) {
1212
query =
1313
// `Query` instance for the `preventDataRacesWithMultipleThreads` query
1414
Concurrency1Package::preventDataRacesWithMultipleThreadsQuery() and
1515
queryId =
1616
// `@id` for the `preventDataRacesWithMultipleThreads` query
1717
"c/cert/prevent-data-races-with-multiple-threads" and
18-
ruleId = "CON32-C"
18+
ruleId = "CON32-C" and
19+
category = "rule"
1920
or
2021
query =
2122
// `Query` instance for the `raceConditionsWhenUsingLibraryFunctions` query
2223
Concurrency1Package::raceConditionsWhenUsingLibraryFunctionsQuery() and
2324
queryId =
2425
// `@id` for the `raceConditionsWhenUsingLibraryFunctions` query
2526
"c/cert/race-conditions-when-using-library-functions" and
26-
ruleId = "CON33-C"
27+
ruleId = "CON33-C" and
28+
category = "rule"
2729
or
2830
query =
2931
// `Query` instance for the `doNotCallSignalInMultithreadedProgram` query
3032
Concurrency1Package::doNotCallSignalInMultithreadedProgramQuery() and
3133
queryId =
3234
// `@id` for the `doNotCallSignalInMultithreadedProgram` query
3335
"c/cert/do-not-call-signal-in-multithreaded-program" and
34-
ruleId = "CON37-C"
36+
ruleId = "CON37-C" and
37+
category = "rule"
3538
}
3639

3740
module Concurrency1Package {

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ newtype Concurrency2Query =
77
TDeadlockByLockingInPredefinedOrderQuery() or
88
TWrapFunctionsThatCanSpuriouslyWakeUpInLoopQuery()
99

10-
predicate isConcurrency2QueryMetadata(Query query, string queryId, string ruleId) {
10+
predicate isConcurrency2QueryMetadata(Query query, string queryId, string ruleId, string category) {
1111
query =
1212
// `Query` instance for the `deadlockByLockingInPredefinedOrder` query
1313
Concurrency2Package::deadlockByLockingInPredefinedOrderQuery() and
1414
queryId =
1515
// `@id` for the `deadlockByLockingInPredefinedOrder` query
1616
"c/cert/deadlock-by-locking-in-predefined-order" and
17-
ruleId = "CON35-C"
17+
ruleId = "CON35-C" and
18+
category = "rule"
1819
or
1920
query =
2021
// `Query` instance for the `wrapFunctionsThatCanSpuriouslyWakeUpInLoop` query
2122
Concurrency2Package::wrapFunctionsThatCanSpuriouslyWakeUpInLoopQuery() and
2223
queryId =
2324
// `@id` for the `wrapFunctionsThatCanSpuriouslyWakeUpInLoop` query
2425
"c/cert/wrap-functions-that-can-spuriously-wake-up-in-loop" and
25-
ruleId = "CON36-C"
26+
ruleId = "CON36-C" and
27+
category = "rule"
2628
}
2729

2830
module Concurrency2Package {

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,42 @@ newtype Concurrency3Query =
99
TPreserveSafetyWhenUsingConditionVariablesQuery() or
1010
TWrapFunctionsThatCanFailSpuriouslyInLoopQuery()
1111

12-
predicate isConcurrency3QueryMetadata(Query query, string queryId, string ruleId) {
12+
predicate isConcurrency3QueryMetadata(Query query, string queryId, string ruleId, string category) {
1313
query =
1414
// `Query` instance for the `doNotAllowAMutexToGoOutOfScopeWhileLocked` query
1515
Concurrency3Package::doNotAllowAMutexToGoOutOfScopeWhileLockedQuery() and
1616
queryId =
1717
// `@id` for the `doNotAllowAMutexToGoOutOfScopeWhileLocked` query
1818
"c/cert/do-not-allow-a-mutex-to-go-out-of-scope-while-locked" and
19-
ruleId = "CON31-C"
19+
ruleId = "CON31-C" and
20+
category = "rule"
2021
or
2122
query =
2223
// `Query` instance for the `doNotDestroyAMutexWhileItIsLocked` query
2324
Concurrency3Package::doNotDestroyAMutexWhileItIsLockedQuery() and
2425
queryId =
2526
// `@id` for the `doNotDestroyAMutexWhileItIsLocked` query
2627
"c/cert/do-not-destroy-a-mutex-while-it-is-locked" and
27-
ruleId = "CON31-C"
28+
ruleId = "CON31-C" and
29+
category = "rule"
2830
or
2931
query =
3032
// `Query` instance for the `preserveSafetyWhenUsingConditionVariables` query
3133
Concurrency3Package::preserveSafetyWhenUsingConditionVariablesQuery() and
3234
queryId =
3335
// `@id` for the `preserveSafetyWhenUsingConditionVariables` query
3436
"c/cert/preserve-safety-when-using-condition-variables" and
35-
ruleId = "CON38-C"
37+
ruleId = "CON38-C" and
38+
category = "rule"
3639
or
3740
query =
3841
// `Query` instance for the `wrapFunctionsThatCanFailSpuriouslyInLoop` query
3942
Concurrency3Package::wrapFunctionsThatCanFailSpuriouslyInLoopQuery() and
4043
queryId =
4144
// `@id` for the `wrapFunctionsThatCanFailSpuriouslyInLoop` query
4245
"c/cert/wrap-functions-that-can-fail-spuriously-in-loop" and
43-
ruleId = "CON41-C"
46+
ruleId = "CON41-C" and
47+
category = "rule"
4448
}
4549

4650
module Concurrency3Package {

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,33 @@ newtype Concurrency4Query =
88
TAppropriateThreadObjectStorageDurationsQuery() or
99
TThreadObjectStorageDurationsNotInitializedQuery()
1010

11-
predicate isConcurrency4QueryMetadata(Query query, string queryId, string ruleId) {
11+
predicate isConcurrency4QueryMetadata(Query query, string queryId, string ruleId, string category) {
1212
query =
1313
// `Query` instance for the `cleanUpThreadSpecificStorage` query
1414
Concurrency4Package::cleanUpThreadSpecificStorageQuery() and
1515
queryId =
1616
// `@id` for the `cleanUpThreadSpecificStorage` query
1717
"c/cert/clean-up-thread-specific-storage" and
18-
ruleId = "CON30-C"
18+
ruleId = "CON30-C" and
19+
category = "rule"
1920
or
2021
query =
2122
// `Query` instance for the `appropriateThreadObjectStorageDurations` query
2223
Concurrency4Package::appropriateThreadObjectStorageDurationsQuery() and
2324
queryId =
2425
// `@id` for the `appropriateThreadObjectStorageDurations` query
2526
"c/cert/appropriate-thread-object-storage-durations" and
26-
ruleId = "CON34-C"
27+
ruleId = "CON34-C" and
28+
category = "rule"
2729
or
2830
query =
2931
// `Query` instance for the `threadObjectStorageDurationsNotInitialized` query
3032
Concurrency4Package::threadObjectStorageDurationsNotInitializedQuery() and
3133
queryId =
3234
// `@id` for the `threadObjectStorageDurationsNotInitialized` query
3335
"c/cert/thread-object-storage-durations-not-initialized" and
34-
ruleId = "CON34-C"
36+
ruleId = "CON34-C" and
37+
category = "rule"
3538
}
3639

3740
module Concurrency4Package {

0 commit comments

Comments
 (0)