Skip to content

Commit a8e993c

Browse files
committed
Fix FP for always-locked fields
1 parent dc2cbf7 commit a8e993c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ predicate alwaysLocked(Field f) {
6868
or
6969
exists(RefType thisType |
7070
forex(VarAccess access |
71-
access = f.getAnAccess() and not access.getEnclosingCallable() instanceof InitializerMethod
71+
access = f.getAnAccess() and
72+
not access.getEnclosingCallable() instanceof Constructor and
73+
not access.getEnclosingCallable() instanceof InitializerMethod
7274
|
7375
locallySynchronizedOnThis(access, thisType)
7476
)

java/ql/test/query-tests/security/CWE-367/semmle/tests/FieldAlwaysLocked.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public FieldAlwaysLocked() {
1414
protected synchronized void checkOut() {
1515
Object o;
1616
if (field.size() > 0) {
17-
Enumeration e = field.keys(); // $ SPURIOUS: Alert
17+
Enumeration e = field.keys();
1818
while (e.hasMoreElements()) {
1919
o = e.nextElement();
20-
field.remove(o); // $ SPURIOUS: Alert
20+
field.remove(o);
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)