bentley/rgbds — pull request #33 by chastai (2014-10-05 16:21:53+00:00)
Title: Fix out of bounds array access on invalid macro arg references 

A reference to an invalid macro argument (\ not followed by a digit
between 1 and 9) will cause an access outside of the bounds of the
currentmacroargs array in sym_FindMacroArg().

Macro arg references are processed in two places:

In CopyMacroArg(): called when scanning tokens between "", {} and
arguments of a macro call. The only problem here is that it accepts \0
as valid and so calls sym_FindMacroArg with a invalid value.

In PutMacroArg(): called by the lexer automata when it encounters a
token matching \\[0-9]? (in other cases than above). So not only it
accepts \0 but also \ alone.
Memo: In setuplex(), a rule is defined with a regex composed of up to
three ranges of chars and takes the form:
[FirstRange]
or [FirstRange][SecondRange]?
or [FirstRange]([SecondRange][Range]*)?
On scanning, when several rules match, the first longuest one is
choosen.

Regression test (the first commit contains an assertion test to detect the OOB error):
1)
SECTION "HOME", HOME
db "\0"

2)
SECTION "HOME", HOME
db \A

3)
SECTION "HOME", HOME
db \