uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit cfeeb85712d335d06372571c9eb2af7bcf7ed15d
parent ffb0a9c9bc7365f4e0579bded134504034536fc6
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sat, 14 Jan 2023 15:08:40 -0800

Catch invalid sublabels

Diffstat:
Msrc/uxnasm.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/uxnasm.c b/src/uxnasm.c @@ -76,6 +76,10 @@ error(const char *name, const char *msg) static char * sublabel(char *src, char *scope, char *name) { + if(slen(scope) + slen(name) >= 0x3f) { + error("Sublabel length too long", name); + return NULL; + } return scat(scat(scpy(scope, src, 0x40), "/"), name); } @@ -178,9 +182,11 @@ makereference(char *scope, char *label, Uint16 addr) if(p.rlen == 0x800) return error("References limit exceeded", label); r = &p.refs[p.rlen++]; - if(label[1] == '&') - scpy(sublabel(subw, scope, label + 2), r->name, 0x40); - else { + if(label[1] == '&') { + if(!sublabel(subw, scope, label + 2)) + return error("Invalid sublabel", label); + scpy(subw, r->name, 0x40); + } else { int pos = spos(label + 1, '/'); if(pos > 0) { Label *l; @@ -287,7 +293,7 @@ parse(char *w, FILE *f) scpy(w + 1, p.scope, 0x40); break; case '&': /* sublabel */ - if(!makelabel(sublabel(subw, p.scope, w + 1))) + if(!sublabel(subw, p.scope, w + 1) || !makelabel(subw)) return error("Invalid sublabel", w); break; case '#': /* literals hex */