From bf23a4e61ddceb26744da8f462ce6351fca66089 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Mon, 7 May 2018 16:18:19 +0200 Subject: cmd/internal/obj/wasm: avoid invalid offsets for Load/Store Offsets for Load and Store instructions have type i32. Bad index expression offsets can cause an offset to be larger than MaxUint32, which is not allowed. One example for this is the test test/index0.go. Generate valid code by adding a guard to the responsible rewrite rule. Also emit a proper error when using such a bad index in assembly code. Change-Id: Ie90adcbf3ae3861c26680eb81790f28692913ccf Reviewed-on: https://go-review.googlesource.com/111955 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/internal/obj/wasm/wasmobj.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/cmd/internal/obj') diff --git a/src/cmd/internal/obj/wasm/wasmobj.go b/src/cmd/internal/obj/wasm/wasmobj.go index 2b7e12a93f..ca09b3fa0b 100644 --- a/src/cmd/internal/obj/wasm/wasmobj.go +++ b/src/cmd/internal/obj/wasm/wasmobj.go @@ -870,6 +870,9 @@ func assemble(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { if p.From.Type != obj.TYPE_CONST { panic("bad type for *Load") } + if p.From.Offset > math.MaxUint32 { + ctxt.Diag("bad offset in %v", p) + } writeUleb128(w, align(p.As)) writeUleb128(w, uint64(p.From.Offset)) @@ -877,6 +880,9 @@ func assemble(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { if p.To.Offset < 0 { panic("negative offset") } + if p.From.Offset > math.MaxUint32 { + ctxt.Diag("bad offset in %v", p) + } writeUleb128(w, align(p.As)) writeUleb128(w, uint64(p.To.Offset)) -- cgit v1.3-5-g9baa