The product does not lock or does not correctly lock a resource when the product must have exclusive access to the resource.
When a resource is not properly locked, an attacker could modify the resource while it is being operated on by the product. This might violate the product's assumption that the resource will not change, potentially leading to unexpected behaviors.
Impact: Modify Application DataDoS: InstabilityDoS: Crash, Exit, or Restart
c
/* access shared resource /
cc
/* access shared resource /
cjava
// variable for bank account balance* private double accountBalance;
java
java
// method to withdraw amount from BankAccount* public void withdraw(double withdrawAmount) { ``` double newBalance = accountBalance - withdrawAmount; accountBalance = newBalance; }
javajava
// synchronized method to deposit amount into BankAccount* public synchronized void deposit(double depositAmount) { ``` ... }
javajava
// lock object for thread access to methods* private ReentrantLock balanceChangeLock;
java
java
// inform other threads that funds are available* sufficientFundsCondition.signalAll(); } catch (Exception e) {...} finally { ``` // unlock lock object balanceChangeLock.unlock(); } }
java
// set lock to block access to BankAccount from other threads* balanceChangeLock.lock(); try { ``` while (balance < amount) {
java