* [PATCH] Always check the result of expect_token while parsing
@ 2021-08-03 22:43 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2021-08-03 22:43 UTC (permalink / raw)
To: gcc-rust; +Cc: Mark Wielaard
When expect_token fails it produces an error and return a
nullptr. Make sure to always check the result of expect_token so we
don't use a nullptr token and crash.
Resolves: https://github.com/Rust-GCC/gccrs/issues/603
---
gcc/rust/parse/rust-parse-impl.h | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 9eb212b4e72..acc9d06acd7 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1898,6 +1898,9 @@ Parser<ManagedTokenSource>::parse_macro_match_fragment ()
// get MacroFragSpec for macro
const_TokenPtr t = expect_token (IDENTIFIER);
+ if (t == nullptr)
+ return nullptr;
+
AST::MacroFragSpec frag = AST::get_frag_spec_from_str (t->get_str ());
if (frag == AST::INVALID)
{
@@ -4325,6 +4328,9 @@ Parser<ManagedTokenSource>::parse_enum (AST::Visibility vis,
// parse enum name
const_TokenPtr enum_name_tok = expect_token (IDENTIFIER);
+ if (enum_name_tok == nullptr)
+ return nullptr;
+
Identifier enum_name = enum_name_tok->get_str ();
// parse generic params (of enum container, not enum variants) if they exist
@@ -4650,6 +4656,9 @@ Parser<ManagedTokenSource>::parse_static_item (AST::Visibility vis,
}
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
if (!skip_token (COLON))
@@ -4700,6 +4709,9 @@ Parser<ManagedTokenSource>::parse_trait (AST::Visibility vis,
// parse trait name
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
// parse generic parameters (if they exist)
@@ -4805,6 +4817,9 @@ Parser<ManagedTokenSource>::parse_trait_item ()
// parse function or method name
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
// parse generic params
@@ -4937,6 +4952,9 @@ Parser<ManagedTokenSource>::parse_trait_type (AST::AttrVec outer_attrs)
skip_token (TYPE);
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
std::vector<std::unique_ptr<AST::TypeParamBound>> bounds;
@@ -4973,6 +4991,9 @@ Parser<ManagedTokenSource>::parse_trait_const (AST::AttrVec outer_attrs)
// parse constant item name
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
if (!skip_token (COLON))
@@ -5338,6 +5359,9 @@ Parser<ManagedTokenSource>::parse_inherent_impl_function_or_method (
// parse function or method name
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
// parse generic params
@@ -14210,6 +14234,9 @@ Parser<ManagedTokenSource>::parse_field_access_expr (
/* get field name identifier (assume that this is a field access expr and not
* await, for instance) */
const_TokenPtr ident_tok = expect_token (IDENTIFIER);
+ if (ident_tok == nullptr)
+ return nullptr;
+
Identifier ident = ident_tok->get_str ();
Location locus = struct_expr->get_locus_slow ();
--
2.32.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-03 22:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 22:43 [PATCH] Always check the result of expect_token while parsing Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).