Skip to content

Commit e395ce7

Browse files
author
ABW
committed
fix nested modify() UB related to updating RC mana (indirect nested modify)
1 parent 3f7cf97 commit e395ce7

3 files changed

Lines changed: 26 additions & 33 deletions

File tree

libraries/chain/database.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ VEST_asset database::adjust_account_vesting_balance(const account_object& to_acc
10151015

10161016
VEST_asset new_vesting = new_vest_balance.as_asset();
10171017
before_vesting_callback( new_vesting );
1018+
if( !is_reward && has_hardfork( HIVE_HARDFORK_0_20 ) )
1019+
rc().regenerate_rc_mana( to_account, _now );
10181020
modify( to_account, [&]( account_object& a )
10191021
{
10201022
if( is_reward )
@@ -1025,15 +1027,12 @@ VEST_asset database::adjust_account_vesting_balance(const account_object& to_acc
10251027
else
10261028
{
10271029
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
1028-
{
10291030
util::update_manabar( cprops, a, new_vesting.get_amount() );
1030-
rc().regenerate_rc_mana( a, _now );
1031-
}
10321031
a.access_vesting().transfer_from( new_vest_balance );
1033-
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
1034-
rc().update_account_after_vest_change( a, _now );
10351032
}
10361033
} );
1034+
if( !is_reward && has_hardfork( HIVE_HARDFORK_0_20 ) )
1035+
rc().update_account_after_vest_change( to_account, _now );
10371036

10381037
return new_vesting;
10391038
}
@@ -1573,9 +1572,8 @@ void database::clear_account( const account_object& account )
15731572
a.delayed_votes.clear();
15741573
a.sum_delayed_votes = 0;
15751574
}
1576-
1577-
rc().update_account_after_vest_change( account, now, true, true );
15781575
} );
1576+
rc().update_account_after_vest_change( account, now, true, true );
15791577

15801578
temp_HIVE_balance hive_from_vests;
15811579
modify( cprops, [&]( dynamic_global_property_object& o )
@@ -3142,16 +3140,14 @@ void database::clear_expired_delegations()
31423140
try{
31433141
pre_push_virtual_operation( *this, vop );
31443142

3143+
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
3144+
rc().regenerate_rc_mana( delegator, now );
31453145
modify( delegator, [&]( account_object& a )
31463146
{
31473147
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
3148-
{
31493148
util::update_manabar( gpo, a, itr->get_vesting().amount.value );
3150-
rc().regenerate_rc_mana( a, now );
3151-
}
3152-
31533149
a.access_delegated_vesting() -= itr->get_vesting();
3154-
});
3150+
} );
31553151
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
31563152
rc().update_account_after_vest_change( delegator, now );
31573153

libraries/chain/database_vesting.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,31 +196,30 @@ void database::process_vesting_withdrawals()
196196

197197
pre_push_virtual_operation( *this, vop );
198198

199+
if( auto_vest_mode && has_hardfork( HIVE_HARDFORK_0_20 ) )
200+
rc().regenerate_rc_mana( to_account, now );
199201
modify( to_account, [&]( account_object& a )
200202
{
201203
if( auto_vest_mode )
202-
{
203-
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
204-
rc().regenerate_rc_mana( a, now );
205204
a.access_vesting().transfer_from( routed_vest_balance );
206-
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
207-
rc().update_account_after_vest_change( a, now );
208-
209-
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
210-
{
211-
FC_ASSERT( dv.valid(), "The object processing `delayed votes` must exist" );
212-
dv->add_votes( _votes_update_data_items, to_self, routed_vests.amount, a );
213-
}
214-
else
215-
{
216-
adjust_proxied_witness_votes( a, routed_vests.amount );
217-
}
205+
else
206+
a.access_hive_balance().transfer_from( routed_hive_balance );
207+
} );
208+
if( auto_vest_mode )
209+
{
210+
if( has_hardfork( HIVE_HARDFORK_0_20 ) )
211+
rc().update_account_after_vest_change( to_account, now );
212+
213+
if( has_hardfork( HIVE_HARDFORK_1_24 ) )
214+
{
215+
FC_ASSERT( dv.valid(), "The object processing `delayed votes` must exist" );
216+
dv->add_votes( _votes_update_data_items, to_self, routed_vests.amount, to_account );
218217
}
219218
else
220219
{
221-
a.access_hive_balance().transfer_from( routed_hive_balance );
220+
adjust_proxied_witness_votes( to_account, routed_vests.amount );
222221
}
223-
} );
222+
}
224223

225224
post_push_virtual_operation( *this, vop );
226225
}

libraries/chain/hive_evaluator_transfer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,15 +695,13 @@ void claim_reward_balance_evaluator::do_apply( const claim_reward_balance_operat
695695
_db.adjust_reward_balance( acnt, hbd_reward, -op_reward_hbd );
696696
_db.adjust_balance( acnt, hbd_reward, op_reward_hbd );
697697

698+
if( _db.has_hardfork( HIVE_HARDFORK_0_20 ) )
699+
_db.rc().regenerate_rc_mana( acnt, now );
698700
temp_HIVE_balance reward_vesting_hive_balance;
699701
_db.modify( acnt, [&]( account_object& a )
700702
{
701703
if( _db.has_hardfork( HIVE_HARDFORK_0_20 ) )
702-
{
703704
util::update_manabar( dgpo, a, op_reward_vests.amount.value );
704-
_db.rc().regenerate_rc_mana( a, now );
705-
}
706-
707705
a.access_vesting().transfer_from( a.access_vest_rewards(), op_reward_vests );
708706
reward_vesting_hive_balance.transfer_from( a.access_vest_rewards_as_hive(), reward_vesting_hive_to_move );
709707
} );

0 commit comments

Comments
 (0)