Skip to content

Commit c5dcdc7

Browse files
committed
Address review comment
1 parent d1ebbd1 commit c5dcdc7

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

c/cert/src/rules/ERR32-C/DoNotRelyOnIndeterminateValuesOfErrno.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AbortCall extends FunctionCall {
3434
* `if (signal(SIGINT, handler) == SIG_ERR)`
3535
*/
3636
class SignalCheckOperation extends EqualityOperation, GuardCondition {
37-
ControlFlowNode errorSuccessor;
37+
BasicBlock errorSuccessor;
3838

3939
SignalCheckOperation() {
4040
this.getAnOperand() = any(MacroInvocation m | m.getMacroName() = "SIG_ERR").getExpr() and
@@ -47,11 +47,11 @@ class SignalCheckOperation extends EqualityOperation, GuardCondition {
4747
)
4848
}
4949

50-
ControlFlowNode getCheckedSuccessor() {
50+
BasicBlock getCheckedSuccessor() {
5151
result != errorSuccessor and result = this.getASuccessor()
5252
}
5353

54-
ControlFlowNode getErrorSuccessor() { result = errorSuccessor }
54+
BasicBlock getErrorSuccessor() { result = errorSuccessor }
5555
}
5656

5757
/**
@@ -71,7 +71,7 @@ class SignalCallingHandler extends Function {
7171
// does not abort on error
7272
not exists(SignalCheckOperation sCheck, AbortCall abort |
7373
DataFlow::localExprFlow(sCall, sCheck.getAnOperand()) and
74-
abort.getEnclosingElement*() = sCheck.getErrorSuccessor()
74+
abort = sCheck.getErrorSuccessor().(BlockStmt).getStmt(0).(ExprStmt).getExpr()
7575
)
7676
)
7777
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| test.c:12:5:12:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:10:21:10:26 | call to signal | call to signal |
2-
| test.c:39:5:39:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:35:21:35:26 | call to signal | call to signal |
3-
| test.c:46:5:46:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:44:21:44:26 | call to signal | call to signal |
4-
| test.c:62:5:62:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:54:17:54:22 | call to signal | call to signal |
5-
| test.c:62:5:62:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:58:17:58:22 | call to signal | call to signal |
2+
| test.c:30:5:30:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:26:21:26:26 | call to signal | call to signal |
3+
| test.c:49:5:49:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:45:21:45:26 | call to signal | call to signal |
4+
| test.c:56:5:56:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:54:21:54:26 | call to signal | call to signal |
5+
| test.c:74:5:74:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:64:17:64:22 | call to signal | call to signal |
6+
| test.c:74:5:74:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:66:17:66:22 | call to signal | call to signal |
7+
| test.c:74:5:74:10 | call to perror | `errno` has indeterminate value after this $@. | test.c:70:17:70:22 | call to signal | call to signal |

c/cert/test/rules/ERR32-C/test.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@ void handler1(int signum) {
1313
}
1414
}
1515

16-
void handler2(int signum) {
16+
void handler2a(int signum) {
1717
pfv old_handler = signal(signum, SIG_DFL);
1818
if (old_handler != SIG_ERR) {
1919
perror(""); // COMPLIANT
2020
} else {
21+
abort(); // COMPLIANT
22+
}
23+
}
24+
25+
void handler2b(int signum) {
26+
pfv old_handler = signal(signum, SIG_DFL);
27+
if (old_handler != SIG_ERR) {
28+
perror(""); // COMPLIANT
29+
} else {
30+
perror(""); // NON_COMPLIANT
2131
abort();
2232
}
2333
}
@@ -46,11 +56,13 @@ int main(void) {
4656
perror(""); // NON_COMPLIANT
4757
}
4858

49-
old_handler = signal(SIGINT, handler2);
59+
old_handler = signal(SIGINT, handler2a);
5060
if (old_handler == SIG_ERR) {
5161
perror(""); // COMPLIANT
5262
}
5363

64+
old_handler = signal(SIGINT, handler2b);
65+
5466
old_handler = signal(SIGINT, handler3);
5567

5668
old_handler = signal(SIGINT, handler4);

0 commit comments

Comments
 (0)