...
Code Block |
---|
|
public class SomeObject {
public synchronized void changeValue() { // Locks on the object's monitor
// ...
}
}
// Untrusted code
SomeObject someObject;
// Initialize someObject = new SomeObject();
synchronized (someObject) {
while (true) {
Thread.sleep(Integer.MAX_VALUE); // Indefinitely delay someObject
}
}
|
...
Code Block |
---|
|
public class SomeObject {
public final Object lock = new Object();
public void changeValue() {
synchronized (lock) {
// ...
}
}
}
// Untrusted code
SomeObject someObject;
// Initialize someObject = new SomeObject();
someObject.lock.wait()
|
Untrusted code that has the ability to create an instance of the class or has access to an already created instance can invoke the wait()
method on the publicly accessible lock
. This causes the lock in the changeValue()
method to be released immediately. Furthermore, if the method invokes lock.wait()
from its body and does not test a condition predicate, it will be vulnerable to malicious notifications. (See CON18-J. Always invoke wait() and await() methods inside a loop for more information.)
...
Code Block |
---|
|
public class SomeObject {
public static synchronized void ChangeValue() { // Locks on the class object's monitor
// ...
}
}
// Untrusted code
SomeObject someObject;
// Initialize someObject
synchronized (someObjectSomeObject.getClass()class) {
while (true) {
Thread.sleep(Integer.MAX_VALUE); // Indefinitely delay someObject
}
}
|
...