diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-06 11:38:28 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-06 11:38:28 -0800 |
commit | 1c62fc77b7ac612f4a09a9b64aa1f6823809665a (patch) | |
tree | 4232003d910e9f8eca9f2ef97afd7a96cbf95816 /src/wasm-interpreter.h | |
parent | 3bb8401c5d8ae826da4ee42f67e7cf2bbda07c57 (diff) | |
download | binaryen-1c62fc77b7ac612f4a09a9b64aa1f6823809665a.tar.gz binaryen-1c62fc77b7ac612f4a09a9b64aa1f6823809665a.tar.bz2 binaryen-1c62fc77b7ac612f4a09a9b64aa1f6823809665a.zip |
trap on runaway recursion
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index a935d2069..0e67a1845 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -26,7 +26,8 @@ int32_t safe_ctz(int32_t v) { } enum { - pageSize = 64*1024 + pageSize = 64*1024, + maxCallDepth = 5000 }; // @@ -66,6 +67,8 @@ public: private: + size_t callDepth = 0; + #ifdef WASM_INTERPRETER_DEBUG int indent = 0; #endif @@ -680,6 +683,9 @@ private: } }; + if (callDepth > maxCallDepth) externalInterface->trap(); + callDepth++; + Function *function = wasm.functionsMap[name]; assert(function); FunctionScope scope(function, arguments); @@ -687,6 +693,7 @@ private: Literal ret = ExpressionRunner(*this, scope).visit(function->body).value; if (function->result == none) ret = Literal(); assert(function->result == ret.type); + callDepth--; return ret; } |