Catch invalid sublabels

This commit is contained in:
Devine Lu Linvega 2023-01-14 15:08:40 -08:00
parent ffb0a9c9bc
commit cfeeb85712
1 changed files with 10 additions and 4 deletions

View File

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