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/13925Reviewed-by: Rob Pike <r@golang.org>
Showing
Please register or sign in to comment