Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
add some dos protection (#8084)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf authored and tomusdrw committed Mar 16, 2018
1 parent 9c2be19 commit e6fd016
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions ethcore/wasm/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ impl<'a> Runtime<'a> {
/// Intuition about the return value sense is to aswer the question 'are we allowed to continue?'
fn charge_gas(&mut self, amount: u64) -> bool {
let prev = self.gas_counter;
if prev + amount > self.gas_limit {
// exceeds gas
false
} else {
self.gas_counter = prev + amount;
true
match prev.checked_add(amount) {
// gas charge overflow protection
None => false,
Some(val) if val > self.gas_limit => false,
Some(_) => {
self.gas_counter = prev + amount;
true
}
}
}

Expand Down Expand Up @@ -522,13 +524,13 @@ impl<'a> Runtime<'a> {

fn debug(&mut self, args: RuntimeArgs) -> Result<()>
{
let msg_ptr: u32 = args.nth(0)?;
let msg_len: u32 = args.nth(1)?;

let msg = String::from_utf8(self.memory.get(msg_ptr, msg_len as usize)?)
.map_err(|_| Error::BadUtf8)?;
trace!(target: "wasm", "Contract debug message: {}", {
let msg_ptr: u32 = args.nth_checked(0)?;
let msg_len: u32 = args.nth_checked(1)?;

trace!(target: "wasm", "Contract debug message: {}", msg);
String::from_utf8(self.memory.get(msg_ptr, msg_len as usize)?)
.map_err(|_| Error::BadUtf8)?
});

Ok(())
}
Expand Down

0 comments on commit e6fd016

Please sign in to comment.