1
0
mirror of https://github.com/golang/go synced 2024-11-19 18:04:40 -07:00

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/90398
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rob Pike 2018-01-29 11:28:17 +11:00
parent 24cdb0f965
commit 8c8bb96b92
2 changed files with 4 additions and 1 deletions

View File

@ -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
}

View File

@ -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"},
}