From f11afd4fcf16350cba29cfdac5f09ef9df7a57a7 Mon Sep 17 00:00:00 2001 From: fsh Date: Tue, 24 Aug 2021 21:46:54 +0200 Subject: [PATCH] [glsl-in] Avoid infinite loop when parsing invalid statements (#1280) --- src/front/glsl/parser/functions.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/front/glsl/parser/functions.rs b/src/front/glsl/parser/functions.rs index e1b41b1bc2..b2db84080f 100644 --- a/src/front/glsl/parser/functions.rs +++ b/src/front/glsl/parser/functions.rs @@ -493,25 +493,16 @@ impl<'source> ParsingContext<'source> { meta } - TokenValue::Plus - | TokenValue::Dash - | TokenValue::Bang - | TokenValue::Tilde - | TokenValue::LeftParen - | TokenValue::Increment - | TokenValue::Decrement - | TokenValue::Identifier(_) - | TokenValue::TypeName(_) - | TokenValue::IntConstant(_) - | TokenValue::BoolConstant(_) - | TokenValue::FloatConstant(_) => { + TokenValue::Semicolon => self.bump(parser)?.meta, + _ => { + // Attempt to force expression parsing for remainder of the + // tokens. Unknown or invalid tokens will be caught there and + // turned into an error. let mut stmt = ctx.stmt_ctx(); let expr = self.parse_expression(parser, ctx, &mut stmt, body)?; ctx.lower(stmt, parser, expr, ExprPos::Rhs, body)?; self.expect(parser, TokenValue::Semicolon)?.meta } - TokenValue::Semicolon => self.bump(parser)?.meta, - _ => meta, }; Ok(Some(meta.union(&meta_rest)))