Skip to content

Commit fdadb8e

Browse files
two-heartripatel-fd
authored andcommitted
codeql: add missing fd_rwlock unlock query
1 parent 26ec626 commit fdadb8e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @name Missing fd_rwlock Unlock
3+
* @description Finds functions where a fd_rwlock is returned on some
4+
* but not all branches. Currently, this query does not model the
5+
* locked data and has no concept of lock semantics (an fd_rwlock_unread
6+
* does not unlock a fd_rwlock_write). If we would ever encounter FPs
7+
* related to this we can later add this more precise modeling.
8+
* @kind problem
9+
* @problem.severity warning
10+
* @precision high
11+
* @id asymmetric-research/missing-rwlock-unlock
12+
*/
13+
14+
import cpp
15+
16+
class LockCall extends FunctionCall {
17+
LockCall() { this.getTarget().hasName(["fd_rwlock_read", "fd_rwlock_write"]) }
18+
}
19+
20+
class UnlockCall extends FunctionCall {
21+
UnlockCall() { this.getTarget().hasName(["fd_rwlock_unread", "fd_rwlock_unwrite"]) }
22+
}
23+
24+
ControlFlowNode nextNoUnlock(ControlFlowNode n) {
25+
not result instanceof UnlockCall and
26+
result = n.getASuccessor()
27+
}
28+
29+
predicate noUnlock(LockCall l) { exists(ReturnStmt r | r = nextNoUnlock*(l)) }
30+
31+
from LockCall l
32+
where
33+
l.getASuccessor*() instanceof UnlockCall and
34+
noUnlock(l)
35+
select l, "Missing unlock"

0 commit comments

Comments
 (0)