aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2018-05-07 16:18:19 +0200
committerCherry Zhang <cherryyz@google.com>2018-05-10 12:05:17 +0000
commitbf23a4e61ddceb26744da8f462ce6351fca66089 (patch)
treed8729a64a59e3d2b0fcbea43ff1a6239bb26e594 /src/cmd/internal/obj
parent10529a01fd8b0d5cc07eb3f6aa00a0272597684b (diff)
downloadgo-bf23a4e61ddceb26744da8f462ce6351fca66089.tar.xz
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 <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/obj')
-rw-r--r--src/cmd/internal/obj/wasm/wasmobj.go6
1 files changed, 6 insertions, 0 deletions
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))