Skip to content

Commit 19da190

Browse files
committed
fixes
1 parent 7a4ca0b commit 19da190

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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.

cpp/common/src/codingstandards/cpp/Concurrency.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

cpp/common/src/codingstandards/cpp/rules/guardaccesstobitfields/GuardAccessToBitFields.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ ControlFlowNode getAReachableLockCFN(MutexFunctionCall mfc) {
4242
query 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
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
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. |

0 commit comments

Comments
 (0)