Skip to content

Commit

Permalink
Prevent integer overflow in analysis
Browse files Browse the repository at this point in the history
Prevent integer overflow when calculating block gas with undefined instructions.
  • Loading branch information
gumb0 authored and chfast committed Jul 16, 2019
1 parent 5db7b35 commit b769597
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/evmone/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ code_analysis analyze(
auto& instr = jumpdest ? analysis.instrs.back() : analysis.instrs.emplace_back(fns[c]);

auto metrics = instr_table[c];
block->gas_cost += metrics.gas_cost;
if (metrics.gas_cost > 0) // can be -1 for undefined instruction
block->gas_cost += metrics.gas_cost;
auto stack_req = metrics.num_stack_arguments - block->stack_diff;
block->stack_diff += (metrics.num_stack_returned_items - metrics.num_stack_arguments);
block->stack_req = std::max(block->stack_req, stack_req);
Expand Down

0 comments on commit b769597

Please sign in to comment.