File tree Expand file tree Collapse file tree 4 files changed +25
-4
lines changed
rules/guardaccesstobitfields
test/rules/guardaccesstobitfields Expand file tree Collapse file tree 4 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 11- ` CON53-CPP ` - ` DeadlockByLockingInPredefinedOrder.ql `
22 - Optimized performance and expanded coverage to include cases where locking
3- order is not serialized
3+ order is not serialized
4+ - ` CON52-CPP ` - ` PreventBitFieldAccessFromMultipleThreads.ql `
5+ - Fixed an issue with RAII-style locks and scope causing locks to not be
6+ correctly identified.
Original file line number Diff line number Diff line change @@ -318,7 +318,7 @@ class RAIIStyleLock extends LockingOperation {
318318 */
319319 override predicate isLock ( ) {
320320 this instanceof ConstructorCall and
321- lock = getArgument ( 0 ) .getAChild ( ) and
321+ lock = getArgument ( 0 ) .getAChild * ( ) and
322322 // defer_locks don't cause a lock
323323 not exists ( Expr exp |
324324 exp = getArgument ( 1 ) and
Original file line number Diff line number Diff line change @@ -42,6 +42,24 @@ ControlFlowNode getAReachableLockCFN(MutexFunctionCall mfc) {
4242query predicate problems ( BitFieldAccess ba , string message ) {
4343 not isExcluded ( ba , getQuery ( ) ) and
4444 ba instanceof ThreadedCFN and
45- not ba instanceof LockProtectedControlFlowNode and
45+ // to be a valid bit field access there must be
46+ // a RAII-style lock before this access
47+ not exists ( RAIIStyleLock lock |
48+ // A lock came before this node
49+ lock = ba .getAPredecessor * ( ) and
50+ lock .isLock ( ) and
51+ // But wasn't followed by an unlock
52+ not exists ( RAIIStyleLock unlock |
53+ // That worked on the same underlying lock variable
54+ unlock .isUnlock ( ) and
55+ unlock .getLock ( ) = lock .getLock ( ) and
56+ // such that the unlock came after the lock
57+ unlock .getAPredecessor * ( ) = lock and
58+ // and after before the access
59+ ba .getAPredecessor * ( ) = unlock
60+ )
61+ ) and
62+ // or the bit field access must be protected by a lock region
63+ not exists ( MutexFunctionCall mfc | ba = getAReachableLockCFN ( mfc ) ) and
4664 message = "Access to a bit-field without a concurrency guard."
4765}
Original file line number Diff line number Diff line change 11| test.cpp:67:7:67:8 | f2 | Access to a bit-field without a concurrency guard. |
22| test.cpp:91:7:91:8 | f2 | Access to a bit-field without a concurrency guard. |
3- | test.cpp:97 :7:97 :8 | f2 | Access to a bit-field without a concurrency guard. |
3+ | test.cpp:102 :7:102 :8 | f2 | Access to a bit-field without a concurrency guard. |
You can’t perform that action at this time.
0 commit comments