add some dos protection (#8084)
This commit is contained in:
parent
e0a21e5aae
commit
58a1671076
@ -173,14 +173,16 @@ 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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge gas according to closure
|
||||
pub fn charge<F>(&mut self, f: F) -> Result<()>
|
||||
@ -548,13 +550,13 @@ impl<'a> Runtime<'a> {
|
||||
|
||||
fn debug(&mut self, args: RuntimeArgs) -> Result<()>
|
||||
{
|
||||
trace!(target: "wasm", "Contract debug message: {}", {
|
||||
let msg_ptr: u32 = args.nth_checked(0)?;
|
||||
let msg_len: u32 = args.nth_checked(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: {}", msg);
|
||||
String::from_utf8(self.memory.get(msg_ptr, msg_len as usize)?)
|
||||
.map_err(|_| Error::BadUtf8)?
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user