Skip to content

Commit 920a2a4

Browse files
committed
packages
1 parent 69a25dd commit 920a2a4

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Concurrency2Query =
7+
TDoNotDestroyAMutexWhileItIsLockedQuery() or
8+
TDeadlockByLockingInPredefinedOrderQuery() or
9+
TWrapFunctionsThatCanSpuriouslyWakeUpInLoopQuery()
10+
11+
predicate isConcurrency2QueryMetadata(Query query, string queryId, string ruleId) {
12+
query =
13+
// `Query` instance for the `doNotDestroyAMutexWhileItIsLocked` query
14+
Concurrency2Package::doNotDestroyAMutexWhileItIsLockedQuery() and
15+
queryId =
16+
// `@id` for the `doNotDestroyAMutexWhileItIsLocked` query
17+
"c/cert/do-not-destroy-a-mutex-while-it-is-locked" and
18+
ruleId = "CON31-C"
19+
or
20+
query =
21+
// `Query` instance for the `deadlockByLockingInPredefinedOrder` query
22+
Concurrency2Package::deadlockByLockingInPredefinedOrderQuery() and
23+
queryId =
24+
// `@id` for the `deadlockByLockingInPredefinedOrder` query
25+
"c/cert/deadlock-by-locking-in-predefined-order" and
26+
ruleId = "CON35-C"
27+
or
28+
query =
29+
// `Query` instance for the `wrapFunctionsThatCanSpuriouslyWakeUpInLoop` query
30+
Concurrency2Package::wrapFunctionsThatCanSpuriouslyWakeUpInLoopQuery() and
31+
queryId =
32+
// `@id` for the `wrapFunctionsThatCanSpuriouslyWakeUpInLoop` query
33+
"c/cert/wrap-functions-that-can-spuriously-wake-up-in-loop" and
34+
ruleId = "CON36-C"
35+
}
36+
37+
module Concurrency2Package {
38+
Query doNotDestroyAMutexWhileItIsLockedQuery() {
39+
//autogenerate `Query` type
40+
result =
41+
// `Query` type for `doNotDestroyAMutexWhileItIsLocked` query
42+
TQueryC(TConcurrency2PackageQuery(TDoNotDestroyAMutexWhileItIsLockedQuery()))
43+
}
44+
45+
Query deadlockByLockingInPredefinedOrderQuery() {
46+
//autogenerate `Query` type
47+
result =
48+
// `Query` type for `deadlockByLockingInPredefinedOrder` query
49+
TQueryC(TConcurrency2PackageQuery(TDeadlockByLockingInPredefinedOrderQuery()))
50+
}
51+
52+
Query wrapFunctionsThatCanSpuriouslyWakeUpInLoopQuery() {
53+
//autogenerate `Query` type
54+
result =
55+
// `Query` type for `wrapFunctionsThatCanSpuriouslyWakeUpInLoop` query
56+
TQueryC(TConcurrency2PackageQuery(TWrapFunctionsThatCanSpuriouslyWakeUpInLoopQuery()))
57+
}
58+
}

cpp/common/src/codingstandards/cpp/exclusions/c/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 Concurrency1
6+
import Concurrency2
67
import IO1
78
import IO2
89
import IO3
@@ -21,6 +22,7 @@ import Syntax
2122
/** The TQuery type representing this language * */
2223
newtype TCQuery =
2324
TConcurrency1PackageQuery(Concurrency1Query q) or
25+
TConcurrency2PackageQuery(Concurrency2Query q) or
2426
TIO1PackageQuery(IO1Query q) or
2527
TIO2PackageQuery(IO2Query q) or
2628
TIO3PackageQuery(IO3Query q) or
@@ -39,6 +41,7 @@ newtype TCQuery =
3941
/** The metadata predicate * */
4042
predicate isQueryMetadata(Query query, string queryId, string ruleId) {
4143
isConcurrency1QueryMetadata(query, queryId, ruleId) or
44+
isConcurrency2QueryMetadata(query, queryId, ruleId) or
4245
isIO1QueryMetadata(query, queryId, ruleId) or
4346
isIO2QueryMetadata(query, queryId, ruleId) or
4447
isIO3QueryMetadata(query, queryId, ruleId) or

rule_packages/c/Concurrency2.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"CERT-C": {
3+
"CON31-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "Allowing a mutex to go out of scope while it is locked removes protections around shared resources.",
10+
"kind": "problem",
11+
"name": "Do not destroy a mutex while it is locked",
12+
"precision": "medium",
13+
"severity": "error",
14+
"short_name": "DoNotDestroyAMutexWhileItIsLocked",
15+
"tags": [
16+
"correctness",
17+
"concurrency"
18+
]
19+
}
20+
],
21+
"title": "Do not destroy a mutex while it is locked"
22+
},
23+
"CON35-C": {
24+
"properties": {
25+
"obligation": "rule"
26+
},
27+
"queries": [
28+
{
29+
"description": "Circular waits leading to thread deadlocks may be avoided by locking in a predefined order.",
30+
"kind": "problem",
31+
"name": "Avoid deadlock by locking in a predefined order",
32+
"precision": "very-high",
33+
"severity": "error",
34+
"short_name": "DeadlockByLockingInPredefinedOrder",
35+
"tags": [
36+
"correctness",
37+
"concurrency"
38+
]
39+
}
40+
],
41+
"title": "Avoid deadlock by locking in a predefined order"
42+
},
43+
"CON36-C": {
44+
"properties": {
45+
"obligation": "rule"
46+
},
47+
"queries": [
48+
{
49+
"description": "Not wrapping functions that can wake up spuriously in a conditioned loop can result race conditions.",
50+
"kind": "problem",
51+
"name": "Wrap functions that can spuriously wake up in a loop",
52+
"precision": "very-high",
53+
"severity": "error",
54+
"short_name": "WrapFunctionsThatCanSpuriouslyWakeUpInLoop",
55+
"tags": [
56+
"correctness",
57+
"concurrency"
58+
]
59+
}
60+
],
61+
"title": "Wrap functions that can spuriously wake up in a loop"
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)