-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathSynchSetUnsynchGet.ql
More file actions
40 lines (38 loc) · 1.1 KB
/
SynchSetUnsynchGet.ql
File metadata and controls
40 lines (38 loc) · 1.1 KB
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
32
33
34
35
36
37
38
39
40
/**
* @name Inconsistently synchronized property
* @description If a property has a lock in its setter, but not in its getter,
* then the value returned by the getter can be inconsistent.
* @kind problem
* @problem.severity error
* @precision medium
* @id cs/unsynchronized-getter
* @tags correctness
* concurrency
* external/cwe/cwe-662
*/
import csharp
from Property p, Field f
where
f.getDeclaringType() = p.getDeclaringType()
and
exists(Setter setter, LockStmt writelock, FieldWrite writeaccess |
p.getSetter() = setter
and
writeaccess = f.getAnAccess()
and
writelock.getEnclosingCallable() = setter
and
writelock.getAChildStmt+().getAChildExpr+() = writeaccess
)
and
exists(Getter getter, FieldRead readaccess |
getter = p.getGetter()
and
readaccess = f.getAnAccess()
and
readaccess.getEnclosingCallable() = getter
and
not exists(LockStmt readlock |
readlock.getAChildStmt+().getAChildExpr+() = readaccess)
)
select p, "Field '$@' is guarded by a lock in the setter but not in the getter.", f, f.getName()