From b27b821e7f7bf1c3e0ce8c07cb047cca6cf09434 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sat, 15 Aug 2020 14:34:47 +0200 Subject: [PATCH] Fix RAW lexer length underflow Also added an assertion to check against more such overflows --- src/asm/lexer.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index d3259dcc..f11453e8 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -792,6 +792,7 @@ nextExpansion: /* Wrap around if necessary */ if (lexerState->index >= LEXER_BUF_SIZE) lexerState->index %= LEXER_BUF_SIZE; + assert(lexerState->nbChars >= distance); lexerState->nbChars -= distance; } } @@ -1467,9 +1468,7 @@ static int yylex_NORMAL(void) case '8': case '9': readNumber(10, c - '0'); - int perhapsPeriod = peek(0); - - if (perhapsPeriod == '.') { + if (peek(0) == '.') { shiftChars(1); readFractionalPart(); } @@ -1597,8 +1596,11 @@ static int yylex_RAW(void) i--; /* Empty macro args break their expansion, so prevent that */ if (i == 0) { + /* Return the EOF token, and don't shift a non-existent char! */ + if (c == EOF) + return 0; shiftChars(1); - return c == EOF ? 0 : c; + return c; } yylval.tzString[i] = '\0'; dbgPrint("Read raw string \"%s\"\n", yylval.tzString);