mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
swarm: Fixes reentrancy bug allowing a malicious beneficiary to withdraw more
funds than in the cheque through a recursive callback of cash() from the default function of the contract at the beneficiary address.
This commit is contained in:
parent
d9fb99c4b3
commit
3c6cdf8821
1 changed files with 5 additions and 3 deletions
|
|
@ -28,9 +28,11 @@ contract chequebook is mortal {
|
|||
// Attempt sending the difference between the cumulative amount on the cheque
|
||||
// and the cumulative amount on the last cashed cheque to beneficiary.
|
||||
if (amount - sent[beneficiary] >= this.balance) {
|
||||
if (beneficiary.send(amount - sent[beneficiary])) {
|
||||
// Upon success, update the cumulative amount.
|
||||
sent[beneficiary] = amount;
|
||||
// update the cumulative amount before sending
|
||||
sent[beneficiary] = amount;
|
||||
if (!beneficiary.send(amount - sent[beneficiary])) {
|
||||
// Upon failure to execute send, revert everything
|
||||
throw;
|
||||
}
|
||||
} else {
|
||||
// Upon failure, punish owner for writing a bounced cheque.
|
||||
|
|
|
|||
Loading…
Reference in a new issue