diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-03-26 00:13:54 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-03-26 21:03:49 +0200 |
| commit | 6abab49029dacfaa616b726f49817213adc1065b (patch) | |
| tree | 05788b57455cdc1bfe5c3175ed417761652cb89f /src/libsyntax/parse | |
| parent | 8f34053f762f708430971a36fc4c6e665528ebe2 (diff) | |
| download | rust-6abab49029dacfaa616b726f49817213adc1065b.tar.gz rust-6abab49029dacfaa616b726f49817213adc1065b.zip | |
syntax: Prevent bumping the parser EOF to stop infinite loops.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 82715f263c9..c6a237d3827 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -254,6 +254,7 @@ pub struct Parser<'a> { /// the previous token or None (only stashed sometimes). pub last_token: Option<Box<token::Token>>, last_token_interpolated: bool, + last_token_eof: bool, pub buffer: [TokenAndSpan; 4], pub buffer_start: isize, pub buffer_end: isize, @@ -366,6 +367,7 @@ impl<'a> Parser<'a> { last_span: span, last_token: None, last_token_interpolated: false, + last_token_eof: false, buffer: [ placeholder.clone(), placeholder.clone(), @@ -998,6 +1000,15 @@ impl<'a> Parser<'a> { /// Advance the parser by one token pub fn bump(&mut self) { + if self.last_token_eof { + // Bumping after EOF is a bad sign, usually an infinite loop. + self.bug("attempted to bump the parser past EOF (may be stuck in a loop)"); + } + + if self.token == token::Eof { + self.last_token_eof = true; + } + self.last_span = self.span; // Stash token for error recovery (sometimes; clone is not necessarily cheap). self.last_token = if self.token.is_ident() || |
