• Didier Spezia's avatar
    cmd/asm: fix several panics with erroneous input · df37c4b9
    Didier Spezia authored
    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: 's avatarRob Pike <r@golang.org>
    df37c4b9
Name
Last commit
Last update
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...