mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
10529a01fd
commit
bf23a4e61d
3 changed files with 34 additions and 33 deletions
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue