Fix buffer overflow when creating patches with long RPN expressions

The createpatch() function was using a fixed-size buffer. I've changed it
to be dynamically allocated. I saw that the RPN format used in patches is
slightly different from the one used internally in the assembler, so I
added a new member to the Expression struct to track the patch size.

I've also limited the RPN expression length to 1MB. I realized that the
patch RPN expression could potentially be longer than the internal RPN
expression, so the internal expression would need a limit smaller than
UINT32_MAX. I thought 1MB would be a reasonable limit.
This commit is contained in:
dbrotz
2019-06-11 09:35:57 -07:00
parent 54e5bf0f0c
commit 015d2b0830
6 changed files with 91 additions and 10 deletions

View File

@@ -0,0 +1,33 @@
SECTION "sec", ROM0
X0 EQUS "0"
m: MACRO
\1 EQUS STRCAT("{X\2}", "+0")
ENDM
n = 0
REPT $7E
n1 = n + 1
NSTR EQUS STRSUB("{n}", 2, STRLEN("{n}") - 1)
N1STR EQUS STRSUB("{n1}", 2, STRLEN("{n1}") - 1)
XN1 EQUS STRCAT("X", "{N1STR}")
m XN1, {NSTR}
PURGE NSTR, N1STR, XN1
n = n + 1
ENDR
; string of 127 zeros separated by plus signs
X EQUS "{X7E}"
db x+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+\
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X
x db 0