Skip to content

Commit 7702e9d

Browse files
committed
Address review comments
1 parent 5c75888 commit 7702e9d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

java/ql/src/Security/CWE/CWE-367/TOCTOURace.ql

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,34 @@ class PossiblyConcurrentCallable extends Callable {
5454
}
5555
}
5656

57+
private VarAccess getANonInitializationAccess(Field f) {
58+
result = f.getAnAccess() and
59+
exists(Callable c | c = result.getEnclosingCallable() |
60+
not (
61+
c = f.getDeclaringType().getACallable() and
62+
(c instanceof Constructor or c instanceof InitializerMethod)
63+
)
64+
)
65+
}
66+
5767
/**
5868
* Holds if all accesses to `v` (outside of initializers) are locked in the same way.
5969
*/
6070
predicate alwaysLocked(Field f) {
6171
exists(Variable lock |
62-
forex(VarAccess access |
63-
access = f.getAnAccess() and not access.getEnclosingCallable() instanceof InitializerMethod
64-
|
72+
forex(VarAccess access | access = getANonInitializationAccess(f) |
6573
locallySynchronizedOn(access, _, lock)
6674
)
6775
)
6876
or
6977
exists(RefType thisType |
70-
forex(VarAccess access |
71-
access = f.getAnAccess() and
72-
not access.getEnclosingCallable() instanceof Constructor and
73-
not access.getEnclosingCallable() instanceof InitializerMethod
74-
|
78+
forex(VarAccess access | access = getANonInitializationAccess(f) |
7579
locallySynchronizedOnThis(access, thisType)
7680
)
7781
)
7882
or
7983
exists(RefType classType |
80-
forex(VarAccess access |
81-
access = f.getAnAccess() and not access.getEnclosingCallable() instanceof InitializerMethod
82-
|
84+
forex(VarAccess access | access = getANonInitializationAccess(f) |
8385
locallySynchronizedOnClass(access, classType)
8486
)
8587
)

0 commit comments

Comments
 (0)