]> Cypherpunks repositories - gostls13.git/commit
cmd/asm: fix several panics with erroneous input
authorDidier Spezia <didier.06@gmail.com>
Wed, 26 Aug 2015 14:27:19 +0000 (14:27 +0000)
committerRob Pike <r@golang.org>
Wed, 2 Sep 2015 20:24:40 +0000 (20:24 +0000)
commitdf37c4b987640849ad2b4033b4f94d7398eceba6
tree8a1ffa731e4ac0d0fe180f97a8813ddffabbe64b
parentdc3540d982ade0d50569abd8d054c9c66e2d9d03
cmd/asm: fix several panics with erroneous input

The parser tries to read as much information as possible,
issuing some errors when needed. Errors generally do not
stop the parsing.

With some pathological input, it may result in various
panics when the error message itself is built, or when the
next operand is parsed. It happens while parsing
pseudo-instructions.

For instance, the following lines all generate a panic:

TEXT
TEXT%
TEXT 1,1
TEXT $"toto", 0, $1
FUNCDATA
DATA 0
DATA(0),1
FUNCDATA(SB
GLOBL 0, 1
PCDATA 1

Added corresponding tests.

Introduced a writer in the parser to capture error messages
for testing purpose. It defaults to os.Stderr.

Added an explicit check when symbol names cannot be displayed.

Interrupted parsing early when the number of operands is wrong for
pseudo-instructions.

Note that the last point is a change of behavior, because some
operands will not get parsed anymore in case of early error.

IMO, it is acceptable, because only the first error of the line
is considered anyway. If it is not acceptable, it can probably
be improved at the price of a more verbose CL.

Fixes #11765
Fixes #11760
Fixes #11759

Change-Id: I9602a848132e358a1bccad794d7555e0823970dd
Reviewed-on: https://go-review.googlesource.com/13925
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/asm/internal/asm/asm.go
src/cmd/asm/internal/asm/parse.go
src/cmd/asm/internal/asm/pseudo_test.go [new file with mode: 0644]