From 39ca1868e3495be75218a44bd2f978d5fc9abd2e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 16 Jan 2022 23:33:07 +0000 Subject: [PATCH] [TS] Empty environment variables as WASI's environ fetch leaks memory --- typescript_strings.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/typescript_strings.py b/typescript_strings.py index 0d9f30b8..3596c2b8 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -73,21 +73,15 @@ imports.wasi_snapshot_preview1 = { // This is called before fd_write to format + print panic messages console.log("wasi_snapshot_preview1:environ_sizes_get"); const out_count_view = new Uint32Array(wasm.memory.buffer, environ_var_count_ptr, 1); - out_count_view[0] = 1; + out_count_view[0] = 0; const out_len_view = new Uint32Array(wasm.memory.buffer, environ_len_ptr, 1); - out_len_view[0] = "RUST_BACKTRACE=1".length + 1; // Note that string must be NULL-terminated + out_len_view[0] = 0; return 0; }, "environ_get": (environ_ptr: number, environ_buf_ptr: number) => { // This is called before fd_write to format + print panic messages console.log("wasi_snapshot_preview1:environ_get"); - const out_ptrs = new Uint32Array(wasm.memory.buffer, environ_ptr, 2); - out_ptrs[0] = environ_buf_ptr; - out_ptrs[1] = "RUST_BACKTRACE=1".length; - const out_environ = new Uint8Array(wasm.memory.buffer, environ_buf_ptr, out_ptrs[1]); - for (var i = 0; i < out_ptrs[1]; i++) { out_environ[i] = "RUST_BACKTRACE=1".codePointAt(i); } - out_environ[out_ptrs[1]] = 0; - return 0; + return 58; // Note supported - we said there were 0 environment entries! }, "proc_exit" : () => { console.log("wasi_snapshot_preview1:proc_exit"); -- 2.39.5