Commit 8c8bb96b authored by Rob Pike's avatar Rob Pike

cmd/asm: fix crash on bad symbol for TEXT

Was missing a check in validSymbol.

Fixes #23580.

Can wait for go1.11. Probably safe but the crash is only for
invalid input, so not worth the risk.

Change-Id: I51f88c5be35a8880536147d1fe5c5dd6798c29de
Reviewed-on: https://go-review.googlesource.com/90398Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 24cdb0f9
......@@ -71,7 +71,7 @@ func (p *Parser) append(prog *obj.Prog, cond string, doLabel bool) {
// validSymbol checks that addr represents a valid name for a pseudo-op.
func (p *Parser) validSymbol(pseudo string, addr *obj.Addr, offsetOk bool) bool {
if addr.Name != obj.NAME_EXTERN && addr.Name != obj.NAME_STATIC || addr.Scale != 0 || addr.Reg != 0 {
if addr.Sym == nil || addr.Name != obj.NAME_EXTERN && addr.Name != obj.NAME_STATIC || addr.Scale != 0 || addr.Reg != 0 {
p.errorf("%s symbol %q must be a symbol(SB)", pseudo, symbolName(addr))
return false
}
......
......@@ -36,13 +36,16 @@ func TestErroneous(t *testing.T) {
{"TEXT", "$\"foo\", 0, $1", "TEXT symbol \"<erroneous symbol>\" must be a symbol(SB)"},
{"TEXT", "$0É:0, 0, $1", "expected end of operand, found É"}, // Issue #12467.
{"TEXT", "$:0:(SB, 0, $1", "expected '(', found 0"}, // Issue 12468.
{"TEXT", "@B(SB),0,$0", "expected '(', found B"}, // Issue 23580.
{"FUNCDATA", "", "expect two operands for FUNCDATA"},
{"FUNCDATA", "(SB ", "expect two operands for FUNCDATA"},
{"DATA", "", "expect two operands for DATA"},
{"DATA", "0", "expect two operands for DATA"},
{"DATA", "(0), 1", "expect /size for DATA argument"},
{"DATA", "@B(SB)/4,0", "expected '(', found B"}, // Issue 23580.
{"GLOBL", "", "expect two or three operands for GLOBL"},
{"GLOBL", "0,1", "GLOBL symbol \"<erroneous symbol>\" must be a symbol(SB)"},
{"GLOBL", "@B(SB), 0", "expected '(', found B"}, // Issue 23580.
{"PCDATA", "", "expect two operands for PCDATA"},
{"PCDATA", "1", "expect two operands for PCDATA"},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment