Skip to content

Commit 61c41f3

Browse files
committed
Package SignalHandlers
1 parent f8c9158 commit 61c41f3

20 files changed

+307
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SIG30-C: Call only asynchronous-safe functions within signal handlers
2+
3+
This query implements the CERT-C rule SIG30-C:
4+
5+
> Call only asynchronous-safe functions within signal handlers
6+
7+
8+
## CERT
9+
10+
** REPLACE THIS BY RUNNING THE SCRIPT `scripts/help/cert-help-extraction.py` **
11+
12+
## Implementation notes
13+
14+
None
15+
16+
## References
17+
18+
* CERT-C: [SIG30-C: Call only asynchronous-safe functions within signal handlers](https://wiki.sei.cmu.edu/confluence/display/c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @id c/cert/call-only-async-safe-functions-within-signal-handlers
3+
* @name SIG30-C: Call only asynchronous-safe functions within signal handlers
4+
* @description Call only asynchronous-safe functions within signal handlers.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/cert/id/sig30-c
9+
* external/cert/obligation/rule
10+
*/
11+
12+
import cpp
13+
import codingstandards.c.cert
14+
15+
from
16+
where
17+
not isExcluded(x, SignalHandlersPackage::callOnlyAsyncSafeFunctionsWithinSignalHandlersQuery()) and
18+
select
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SIG31-C: Do not access shared objects in signal handlers
2+
3+
This query implements the CERT-C rule SIG31-C:
4+
5+
> Do not access shared objects in signal handlers
6+
7+
8+
## CERT
9+
10+
** REPLACE THIS BY RUNNING THE SCRIPT `scripts/help/cert-help-extraction.py` **
11+
12+
## Implementation notes
13+
14+
None
15+
16+
## References
17+
18+
* CERT-C: [SIG31-C: Do not access shared objects in signal handlers](https://wiki.sei.cmu.edu/confluence/display/c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @id c/cert/do-not-access-shared-objects-in-signal-handlers
3+
* @name SIG31-C: Do not access shared objects in signal handlers
4+
* @description Do not access shared objects in signal handlers.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/cert/id/sig31-c
9+
* external/cert/obligation/rule
10+
*/
11+
12+
import cpp
13+
import codingstandards.c.cert
14+
15+
from
16+
where
17+
not isExcluded(x, SignalHandlersPackage::doNotAccessSharedObjectsInSignalHandlersQuery()) and
18+
select
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SIG34-C: Do not call signal() from within interruptible signal handlers
2+
3+
This query implements the CERT-C rule SIG34-C:
4+
5+
> Do not call signal() from within interruptible signal handlers
6+
7+
8+
## CERT
9+
10+
** REPLACE THIS BY RUNNING THE SCRIPT `scripts/help/cert-help-extraction.py` **
11+
12+
## Implementation notes
13+
14+
None
15+
16+
## References
17+
18+
* CERT-C: [SIG34-C: Do not call signal() from within interruptible signal handlers](https://wiki.sei.cmu.edu/confluence/display/c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @id c/cert/do-not-call-signal-from-interruptible-signal-handlers
3+
* @name SIG34-C: Do not call signal() from within interruptible signal handlers
4+
* @description Do not call signal() from within interruptible signal handlers.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/cert/id/sig34-c
9+
* external/cert/obligation/rule
10+
*/
11+
12+
import cpp
13+
import codingstandards.c.cert
14+
15+
from
16+
where
17+
not isExcluded(x, SignalHandlersPackage::doNotCallSignalFromInterruptibleSignalHandlersQuery()) and
18+
select
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SIG35-C: Do not return from a computational exception signal handler
2+
3+
This query implements the CERT-C rule SIG35-C:
4+
5+
> Do not return from a computational exception signal handler
6+
## CERT
7+
8+
** REPLACE THIS BY RUNNING THE SCRIPT `scripts/help/cert-help-extraction.py` **
9+
10+
## Implementation notes
11+
12+
None
13+
14+
## References
15+
16+
* CERT-C: [SIG35-C: Do not return from a computational exception signal handler](https://wiki.sei.cmu.edu/confluence/display/c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @id c/cert/do-not-return-from-a-computational-exception-handler
3+
* @name SIG35-C: Do not return from a computational exception signal handler
4+
* @description Do not return from a computational exception signal handler.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/cert/id/sig35-c
9+
* external/cert/obligation/rule
10+
*/
11+
12+
import cpp
13+
import codingstandards.c.cert
14+
15+
from
16+
where
17+
not isExcluded(x, SignalHandlersPackage::doNotReturnFromAComputationalExceptionHandlerQuery()) and
18+
select
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/SIG30-C/CallOnlyAsyncSafeFunctionsWithinSignalHandlers.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/SIG34-C/DoNotCallSignalFromInterruptibleSignalHandlers.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/SIG35-C/DoNotReturnFromAComputationalExceptionHandler.ql

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

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import Preprocessor5
4646
import Preprocessor6
4747
import SideEffects1
4848
import SideEffects2
49+
import SignalHandlers
4950
import Strings1
5051
import Strings2
5152
import Strings3
@@ -97,6 +98,7 @@ newtype TCQuery =
9798
TPreprocessor6PackageQuery(Preprocessor6Query q) or
9899
TSideEffects1PackageQuery(SideEffects1Query q) or
99100
TSideEffects2PackageQuery(SideEffects2Query q) or
101+
TSignalHandlersPackageQuery(SignalHandlersQuery q) or
100102
TStrings1PackageQuery(Strings1Query q) or
101103
TStrings2PackageQuery(Strings2Query q) or
102104
TStrings3PackageQuery(Strings3Query q) or
@@ -148,6 +150,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
148150
isPreprocessor6QueryMetadata(query, queryId, ruleId, category) or
149151
isSideEffects1QueryMetadata(query, queryId, ruleId, category) or
150152
isSideEffects2QueryMetadata(query, queryId, ruleId, category) or
153+
isSignalHandlersQueryMetadata(query, queryId, ruleId, category) or
151154
isStrings1QueryMetadata(query, queryId, ruleId, category) or
152155
isStrings2QueryMetadata(query, queryId, ruleId, category) or
153156
isStrings3QueryMetadata(query, queryId, ruleId, category) or
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype SignalHandlersQuery =
7+
TCallOnlyAsyncSafeFunctionsWithinSignalHandlersQuery() or
8+
TDoNotAccessSharedObjectsInSignalHandlersQuery() or
9+
TDoNotCallSignalFromInterruptibleSignalHandlersQuery() or
10+
TDoNotReturnFromAComputationalExceptionHandlerQuery()
11+
12+
predicate isSignalHandlersQueryMetadata(Query query, string queryId, string ruleId, string category) {
13+
query =
14+
// `Query` instance for the `callOnlyAsyncSafeFunctionsWithinSignalHandlers` query
15+
SignalHandlersPackage::callOnlyAsyncSafeFunctionsWithinSignalHandlersQuery() and
16+
queryId =
17+
// `@id` for the `callOnlyAsyncSafeFunctionsWithinSignalHandlers` query
18+
"c/cert/call-only-async-safe-functions-within-signal-handlers" and
19+
ruleId = "SIG30-C" and
20+
category = "rule"
21+
or
22+
query =
23+
// `Query` instance for the `doNotAccessSharedObjectsInSignalHandlers` query
24+
SignalHandlersPackage::doNotAccessSharedObjectsInSignalHandlersQuery() and
25+
queryId =
26+
// `@id` for the `doNotAccessSharedObjectsInSignalHandlers` query
27+
"c/cert/do-not-access-shared-objects-in-signal-handlers" and
28+
ruleId = "SIG31-C" and
29+
category = "rule"
30+
or
31+
query =
32+
// `Query` instance for the `doNotCallSignalFromInterruptibleSignalHandlers` query
33+
SignalHandlersPackage::doNotCallSignalFromInterruptibleSignalHandlersQuery() and
34+
queryId =
35+
// `@id` for the `doNotCallSignalFromInterruptibleSignalHandlers` query
36+
"c/cert/do-not-call-signal-from-interruptible-signal-handlers" and
37+
ruleId = "SIG34-C" and
38+
category = "rule"
39+
or
40+
query =
41+
// `Query` instance for the `doNotReturnFromAComputationalExceptionHandler` query
42+
SignalHandlersPackage::doNotReturnFromAComputationalExceptionHandlerQuery() and
43+
queryId =
44+
// `@id` for the `doNotReturnFromAComputationalExceptionHandler` query
45+
"c/cert/do-not-return-from-a-computational-exception-handler" and
46+
ruleId = "SIG35-C" and
47+
category = "rule"
48+
}
49+
50+
module SignalHandlersPackage {
51+
Query callOnlyAsyncSafeFunctionsWithinSignalHandlersQuery() {
52+
//autogenerate `Query` type
53+
result =
54+
// `Query` type for `callOnlyAsyncSafeFunctionsWithinSignalHandlers` query
55+
TQueryC(TSignalHandlersPackageQuery(TCallOnlyAsyncSafeFunctionsWithinSignalHandlersQuery()))
56+
}
57+
58+
Query doNotAccessSharedObjectsInSignalHandlersQuery() {
59+
//autogenerate `Query` type
60+
result =
61+
// `Query` type for `doNotAccessSharedObjectsInSignalHandlers` query
62+
TQueryC(TSignalHandlersPackageQuery(TDoNotAccessSharedObjectsInSignalHandlersQuery()))
63+
}
64+
65+
Query doNotCallSignalFromInterruptibleSignalHandlersQuery() {
66+
//autogenerate `Query` type
67+
result =
68+
// `Query` type for `doNotCallSignalFromInterruptibleSignalHandlers` query
69+
TQueryC(TSignalHandlersPackageQuery(TDoNotCallSignalFromInterruptibleSignalHandlersQuery()))
70+
}
71+
72+
Query doNotReturnFromAComputationalExceptionHandlerQuery() {
73+
//autogenerate `Query` type
74+
result =
75+
// `Query` type for `doNotReturnFromAComputationalExceptionHandler` query
76+
TQueryC(TSignalHandlersPackageQuery(TDoNotReturnFromAComputationalExceptionHandlerQuery()))
77+
}
78+
}

rule_packages/c/SignalHandlers.json

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"CERT-C": {
3+
"SIG30-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "Call only asynchronous-safe functions within signal handlers.",
10+
"kind": "problem",
11+
"name": "Call only asynchronous-safe functions within signal handlers",
12+
"precision": "very-high",
13+
"severity": "error",
14+
"short_name": "CallOnlyAsyncSafeFunctionsWithinSignalHandlers",
15+
"tags": []
16+
}
17+
],
18+
"title": "Call only asynchronous-safe functions within signal handlers"
19+
},
20+
"SIG31-C": {
21+
"properties": {
22+
"obligation": "rule"
23+
},
24+
"queries": [
25+
{
26+
"description": "Do not access shared objects in signal handlers.",
27+
"kind": "problem",
28+
"name": "Do not access shared objects in signal handlers",
29+
"precision": "very-high",
30+
"severity": "error",
31+
"short_name": "DoNotAccessSharedObjectsInSignalHandlers",
32+
"tags": []
33+
}
34+
],
35+
"title": "Do not access shared objects in signal handlers"
36+
},
37+
"SIG34-C": {
38+
"properties": {
39+
"obligation": "rule"
40+
},
41+
"queries": [
42+
{
43+
"description": "Do not call signal() from within interruptible signal handlers.",
44+
"kind": "problem",
45+
"name": "Do not call signal() from within interruptible signal handlers",
46+
"precision": "very-high",
47+
"severity": "error",
48+
"short_name": "DoNotCallSignalFromInterruptibleSignalHandlers",
49+
"tags": []
50+
}
51+
],
52+
"title": "Do not call signal() from within interruptible signal handlers"
53+
},
54+
"SIG35-C": {
55+
"properties": {
56+
"obligation": "rule"
57+
},
58+
"queries": [
59+
{
60+
"description": "Do not return from a computational exception signal handler.",
61+
"kind": "problem",
62+
"name": "Do not return from a computational exception signal handler",
63+
"precision": "very-high",
64+
"severity": "error",
65+
"short_name": "DoNotReturnFromAComputationalExceptionHandler",
66+
"tags": []
67+
}
68+
],
69+
"title": "Do not return from a computational exception signal handler"
70+
}
71+
}
72+
}

rules.csv

+4-4
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,10 @@ c,CERT-C,POS54-C,OutOfScope,Rule,,,Detect and handle POSIX library errors,,,,
588588
c,CERT-C,PRE30-C,No,Rule,,,Do not create a universal character name through concatenation,,,Medium,
589589
c,CERT-C,PRE31-C,Yes,Rule,,,Avoid side effects in arguments to unsafe macros,RULE-13-2,SideEffects,Medium,
590590
c,CERT-C,PRE32-C,Yes,Rule,,,Do not use preprocessor directives in invocations of function-like macros,,Preprocessor5,Hard,
591-
c,CERT-C,SIG30-C,Yes,Rule,,,Call only asynchronous-safe functions within signal handlers,,Contracts,Medium,
592-
c,CERT-C,SIG31-C,Yes,Rule,,,Do not access shared objects in signal handlers,,Contracts,Medium,
593-
c,CERT-C,SIG34-C,Yes,Rule,,,Do not call signal() from within interruptible signal handlers,,Contracts,Medium,
594-
c,CERT-C,SIG35-C,Yes,Rule,,,Do not return from a computational exception signal handler,,Contracts,Easy,
591+
c,CERT-C,SIG30-C,Yes,Rule,,,Call only asynchronous-safe functions within signal handlers,,SignalHandlers,Medium,
592+
c,CERT-C,SIG31-C,Yes,Rule,,,Do not access shared objects in signal handlers,,SignalHandlers,Medium,
593+
c,CERT-C,SIG34-C,Yes,Rule,,,Do not call signal() from within interruptible signal handlers,,SignalHandlers,Medium,
594+
c,CERT-C,SIG35-C,Yes,Rule,,,Do not return from a computational exception signal handler,,SignalHandlers,Easy,
595595
c,CERT-C,STR30-C,Yes,Rule,,,Do not attempt to modify string literals,,Strings1,Medium,
596596
c,CERT-C,STR31-C,Yes,Rule,,,Guarantee that storage for strings has sufficient space for character data and the null terminator,STR50-CPP,Strings1,Very Hard,
597597
c,CERT-C,STR32-C,Yes,Rule,,,Do not pass a non-null-terminated character sequence to a library function that expects a string,STR51-CPP,Strings1,Very Hard,

0 commit comments

Comments
 (0)