-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFutileSyncOnField.ql
More file actions
31 lines (28 loc) · 909 Bytes
/
FutileSyncOnField.ql
File metadata and controls
31 lines (28 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @name Futile synchronization on field
* @description Synchronizing on a field and updating that field while the lock is held is unlikely
* to provide the desired thread safety.
* @kind problem
* @problem.severity error
* @precision high
* @id cs/unsafe-sync-on-field
* @tags quality
* reliability
* concurrency
* correctness
* external/cwe/cwe-662
* external/cwe/cwe-366
*/
import csharp
predicate lockedFieldUpdate(LockStmt lock, Field f, AssignableDefinition def) {
lock.getAChild+() = def.getExpr() and
def.getTarget() = f
}
from LockStmt lock, Expr e, Field f, AssignableDefinition def
where
e = lock.getExpr() and
f.getAnAccess() = e and
lockedFieldUpdate(lock, f, def)
select e,
"Locking field $@ guards the initial value, not the value which may be seen from another thread after $@.",
f, f.getName(), def, "reassignment"