diff options
author | Daniel A. Nagy <nagy.da@gmail.com> | 2016-08-30 21:53:14 +0800 |
---|---|---|
committer | Daniel A. Nagy <nagy.da@gmail.com> | 2016-08-31 00:16:49 +0800 |
commit | 7b884e0075cba9033dadf2d8ed0bf092193d2ae5 (patch) | |
tree | ab96c3063cd8f9a9bc9d88646dcb1a74554e8717 /contracts/chequebook/contract/chequebook.sol | |
parent | 3e7b4ae0c3fda9d71bcae4274b0af4b075977b8b (diff) | |
download | go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.tar go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.tar.gz go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.tar.bz2 go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.tar.lz go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.tar.xz go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.tar.zst go-tangerine-7b884e0075cba9033dadf2d8ed0bf092193d2ae5.zip |
contracts/chequebook/contract: fix possible reentrancy bug in chequebook.sol
Diffstat (limited to 'contracts/chequebook/contract/chequebook.sol')
-rw-r--r-- | contracts/chequebook/contract/chequebook.sol | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/contracts/chequebook/contract/chequebook.sol b/contracts/chequebook/contract/chequebook.sol index cb19d0b27..eefe6c063 100644 --- a/contracts/chequebook/contract/chequebook.sol +++ b/contracts/chequebook/contract/chequebook.sol @@ -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. |