diff options
author | Alon Zakai <azakai@google.com> | 2020-10-12 17:11:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 17:11:30 -0700 |
commit | 5ae1724add800780475e02e05a4af133e3729bd6 (patch) | |
tree | 7cc9dec3bdd3fc27971b7ade1112402bda3fec64 /src/wasm-interpreter.h | |
parent | d38ddda4c299a40ee48efb777ec69c823312c9dd (diff) | |
download | binaryen-5ae1724add800780475e02e05a4af133e3729bd6.tar.gz binaryen-5ae1724add800780475e02e05a4af133e3729bd6.tar.bz2 binaryen-5ae1724add800780475e02e05a4af133e3729bd6.zip |
Interpreter: Add a limit to how much we try to grow memory, to avoid DOS (#3227)
growMemory() now also returns whether we succeeded.
Without this it could eventually start to swap etc., which is annoying.
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index b683de632..203786e72 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1685,7 +1685,7 @@ public: LiteralList& arguments, Type result, SubType& instance) = 0; - virtual void growMemory(Address oldSize, Address newSize) = 0; + virtual bool growMemory(Address oldSize, Address newSize) = 0; virtual void trap(const char* why) = 0; virtual void throwException(Literal exnref) = 0; @@ -2406,8 +2406,13 @@ private: if (newSize > instance.wasm.memory.max) { return fail; } - instance.externalInterface->growMemory( - instance.memorySize * Memory::kPageSize, newSize * Memory::kPageSize); + if (!instance.externalInterface->growMemory( + instance.memorySize * Memory::kPageSize, + newSize * Memory::kPageSize)) { + // We failed to grow the memory in practice, even though it was valid + // to try to do so. + return fail; + } instance.memorySize = newSize; return ret; } |