From 424702b272c78e1bc5a9e383948561f569467cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20Sta=C3=AFesse?= Date: Tue, 1 Apr 2014 16:48:26 +0200 Subject: [PATCH] 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. --- src/asm/globlex.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/asm/globlex.c b/src/asm/globlex.c index c26cdc4d..88ae4167 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -219,9 +219,15 @@ PutMacroArg(char *src, ULONG size) 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); }