@@ -15,10 +15,20 @@ import codingstandards.c.cert
15
15
import codingstandards.c.Errno
16
16
import semmle.code.cpp.controlflow.Guards
17
17
18
+ /**
19
+ * A call to function `signal`
20
+ */
18
21
class SignalCall extends FunctionCall {
19
22
SignalCall ( ) { this .getTarget ( ) .hasGlobalName ( "signal" ) }
20
23
}
21
24
25
+ /**
26
+ * A call to `abort` or `_Exit`
27
+ */
28
+ class AbortCall extends FunctionCall {
29
+ AbortCall ( ) { this .getTarget ( ) .hasGlobalName ( [ "abort" , "_Exit" ] ) }
30
+ }
31
+
22
32
/**
23
33
* A check on `signal` call return value
24
34
* `if (signal(SIGINT, handler) == SIG_ERR)`
@@ -59,9 +69,8 @@ class SignalCallingHandler extends Function {
59
69
DataFlow:: localFlow ( DataFlow:: parameterNode ( this .getParameter ( 0 ) ) ,
60
70
DataFlow:: exprNode ( sCall .getArgument ( 0 ) ) ) and
61
71
// does not abort on error
62
- not exists ( SignalCheckOperation sCheck , FunctionCall abort |
72
+ not exists ( SignalCheckOperation sCheck , AbortCall abort |
63
73
DataFlow:: localExprFlow ( sCall , sCheck .getAnOperand ( ) ) and
64
- abort .getTarget ( ) .hasGlobalName ( [ "abort" , "_Exit" ] ) and
65
74
abort .getEnclosingElement * ( ) = sCheck .getErrorSuccessor ( )
66
75
)
67
76
)
@@ -80,7 +89,7 @@ ControlFlowNode preceedErrnoRead(ErrnoRead er) {
80
89
result = mid .getAPredecessor ( ) and
81
90
mid = preceedErrnoRead ( er ) and
82
91
// stop recursion on calls to `abort` and `_Exit`
83
- not result . ( FunctionCall ) . getTarget ( ) . hasGlobalName ( [ "abort" , "_Exit" ] ) and
92
+ not result instanceof AbortCall and
84
93
// stop recursion on successful `SignalCheckOperation`
85
94
not result = any ( SignalCheckOperation o ) .getCheckedSuccessor ( )
86
95
)
0 commit comments