Skip to content

Commit 3339c1f

Browse files
authored
Fuzzer: Fix handling of JS null exceptions (#7303)
We have a test try { .. } catch (e) { e.a; // must be valid } That test will catch various wasm exception issues, but it turns out that it also fails on one specific JS exception: null. It is ok to do `e.a` on numbers, objects, anything really, all except for null. This PR adds a guard for that.
1 parent 924c32b commit 3339c1f

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

scripts/fuzz_shell.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ function callFunc(func) {
178178
/* await */ func();
179179
return 0;
180180
} catch (e) {
181-
// The exception must exist, and not behave oddly when we access a
182-
// property on it. (VM bugs could cause errors here.)
183-
e.a;
181+
// The exception might be a JS null, but otherwise it must be valid to check
182+
// if a property exists on it (VM bugs could cause errors here, specifically
183+
// if a wasm exception is caught here, and it is not represented properly).
184+
if (e !== null) e.a;
184185

185186
// We only want to catch exceptions, not wasm traps: traps should still
186187
// halt execution. Handling this requires different code in wasm2js, so

test/lit/d8/fuzz_shell_exceptions.wast

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
(i32.const 42)
2121
)
2222
)
23+
24+
(func $throwing-jstag-null (export "throwing-jstag-null")
25+
;; Throwing JSTag leads to the JS side receiving the externref as a JS
26+
;; value. A null must be handled properly while doing so, without error, and
27+
;; be logged as a null.
28+
(throw $imported-js-tag
29+
(ref.null noextern)
30+
)
31+
)
2332
)
2433

2534
;; Build to a binary wasm.
@@ -34,6 +43,8 @@
3443
;; CHECK: exception thrown: Error: js exception
3544
;; CHECK: [fuzz-exec] calling throwing-tag
3645
;; CHECK: exception thrown: [object WebAssembly.Exception]
46+
;; CHECK: [fuzz-exec] calling throwing-jstag-null
47+
;; CHECK: exception thrown: null
3748

3849

3950

0 commit comments

Comments
 (0)