@@ -15,10 +15,20 @@ import codingstandards.c.cert
1515import codingstandards.c.Errno
1616import semmle.code.cpp.controlflow.Guards
1717
18+ /**
19+ * A call to function `signal`
20+ */
1821class SignalCall extends FunctionCall {
1922 SignalCall() { this.getTarget().hasGlobalName("signal") }
2023}
2124
25+ /**
26+ * A call to `abort` or `_Exit`
27+ */
28+ class AbortCall extends FunctionCall {
29+ AbortCall() { this.getTarget().hasGlobalName(["abort", "_Exit"]) }
30+ }
31+
2232/**
2333 * A check on `signal` call return value
2434 * `if (signal(SIGINT, handler) == SIG_ERR)`
@@ -59,9 +69,8 @@ class SignalCallingHandler extends Function {
5969 DataFlow::localFlow(DataFlow::parameterNode(this.getParameter(0)),
6070 DataFlow::exprNode(sCall.getArgument(0))) and
6171 // does not abort on error
62- not exists(SignalCheckOperation sCheck, FunctionCall abort |
72+ not exists(SignalCheckOperation sCheck, AbortCall abort |
6373 DataFlow::localExprFlow(sCall, sCheck.getAnOperand()) and
64- abort.getTarget().hasGlobalName(["abort", "_Exit"]) and
6574 abort.getEnclosingElement*() = sCheck.getErrorSuccessor()
6675 )
6776 )
@@ -80,7 +89,7 @@ ControlFlowNode preceedErrnoRead(ErrnoRead er) {
8089 result = mid.getAPredecessor() and
8190 mid = preceedErrnoRead(er) and
8291 // stop recursion on calls to `abort` and `_Exit`
83- not result.(FunctionCall).getTarget().hasGlobalName(["abort", "_Exit"]) and
92+ not result instanceof AbortCall and
8493 // stop recursion on successful `SignalCheckOperation`
8594 not result = any(SignalCheckOperation o).getCheckedSuccessor()
8695 )
0 commit comments