From: Owen Avery Date: Sat, 17 Jun 2023 04:32:38 +0000 (-0400) Subject: gccrs: Prevent invalid iterator dereference X-Git-Tag: basepoints/gcc-15~2464 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45c01fae2a2afb30b0ca933e9d7b807acb167d23;p=thirdparty%2Fgcc.git gccrs: Prevent invalid iterator dereference gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::classify_keyword): Check if iterator is valid before dereferencing. Signed-off-by: Owen Avery --- diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index c910c7cf83ad..23579e519443 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -255,11 +255,12 @@ TokenId Lexer::classify_keyword (const std::string &str) { auto keyword = keywords.find (str); - auto id = keyword->second; if (keyword == keywords.end ()) return IDENTIFIER; + auto id = keyword->second; + // We now have the expected token ID of the reserved keyword. However, some // keywords are reserved starting in certain editions. For example, `try` is // only a reserved keyword in editions >=2018. The language might gain new