From: Matt Corallo Date: Sun, 16 Jan 2022 23:33:07 +0000 (+0000) Subject: [TS] Empty environment variables as WASI's environ fetch leaks memory X-Git-Tag: v0.0.105.0~5^2~10 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=39ca1868e3495be75218a44bd2f978d5fc9abd2e;p=ldk-java [TS] Empty environment variables as WASI's environ fetch leaks memory --- 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");