From 8bb5902e14fb9b89b86fa0c16c25717f83475849 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 4 Mar 2007 01:53:50 +0000 Subject: [PATCH] GAS parser: fix unterminated string handling to properly handle EOF. Found by: zzuf (http://sam.zoy.org/zzuf/) svn path=/trunk/yasm/; revision=1809 --- modules/parsers/gas/gas-token.re | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/parsers/gas/gas-token.re b/modules/parsers/gas/gas-token.re index 4f4e2184..eca535bd 100644 --- a/modules/parsers/gas/gas-token.re +++ b/modules/parsers/gas/gas-token.re @@ -214,10 +214,6 @@ static size_t strbuf_size = 0; static void strbuf_append(size_t count, YYCTYPE *cursor, yasm_scanner *s, int ch) { - if (cursor == s->eof) - yasm_error_set(YASM_ERROR_SYNTAX, - N_("unexpected end of file in string")); - if (count >= strbuf_size) { strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE); strbuf_size += STRBUF_ALLOC_SIZE; @@ -677,6 +673,13 @@ stringconst_scan: /*!re2c /* Handle escaped double-quote by copying and continuing */ "\\\"" { + if (cursor == s->eof) { + yasm_error_set(YASM_ERROR_SYNTAX, + N_("unexpected end of file in string")); + lvalp->str.contents = (char *)strbuf; + lvalp->str.len = count; + RETURN(STRING); + } strbuf_append(count++, cursor, s, '"'); goto stringconst_scan; } @@ -690,6 +693,13 @@ stringconst_scan: } any { + if (cursor == s->eof) { + yasm_error_set(YASM_ERROR_SYNTAX, + N_("unexpected end of file in string")); + lvalp->str.contents = (char *)strbuf; + lvalp->str.len = count; + RETURN(STRING); + } strbuf_append(count++, cursor, s, s->tok[0]); goto stringconst_scan; } -- 2.40.0