shithub: rgbds

Download patch

ref: 424702b272c78e1bc5a9e383948561f569467cde
parent: 00de7674af6d7636e99c057f52d1913142454b85
author: Christophe Staïesse <[email protected]>
date: Tue Apr 1 12:48:26 EDT 2014

Fix bug: rgbasm segfault when \@ is used outside a macro

The problem occurs when \@ is accessed outside the definition of a
macro and is not between "" or {}, or when it is used in an argument of
a macro call, i.e. when the access is processed by PutUniqueArg().

PutUniqueArg(), puts back the string value of \@ to the lexer's buffer
(to substitute \@ by the unique label string).
When \@ is not defined, sym_FindMacroArg(-1) returns NULL, which
yyunputstr() doesn't expect and crashes.

Solution:
Generate an error when \@ is not defined.

Regression test:

SECTION "HOME", HOME
        ld a,\@

Will segfault.
On the fixed version, it will return an error as \@ is not available.

--- a/src/asm/globlex.c
+++ b/src/asm/globlex.c
@@ -219,9 +219,15 @@
 ULONG 
 PutUniqueArg(char *src, ULONG size)
 {
+	char *s;
+
 	src = src;
 	yyskipbytes(size);
-	yyunputstr(sym_FindMacroArg(-1));
+	if ((s = sym_FindMacroArg(-1)) != NULL) {
+		yyunputstr(s);
+	} else {
+		yyerror("Macro unique label string not defined");
+	}
 	return (0);
 }