From 0ba57d2457b8341c0ba912cdde12872a349da3b3 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 1 Jun 2022 07:57:04 +0200 Subject: vhdl-parse: avoid a crash on too large numbers. For #2070 --- src/vhdl/vhdl-parse.adb | 9 ++++++++- src/vhdl/vhdl-parse_psl.adb | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vhdl/vhdl-parse.adb b/src/vhdl/vhdl-parse.adb index 48c6de4c9..0266a494e 100644 --- a/src/vhdl/vhdl-parse.adb +++ b/src/vhdl/vhdl-parse.adb @@ -6320,7 +6320,14 @@ package body Vhdl.Parse is Scan; -- Resize. - Resize_Bit_String (Res, Nat32 (Int)); + if Int > 2048 then + -- What is a reasonable limit ? + Error_Msg_Parse + (Get_Token_Location, + "bit string size is too large (> 2048)"); + else + Resize_Bit_String (Res, Nat32 (Int)); + end if; else Error_Msg_Parse (Get_Token_Location, diff --git a/src/vhdl/vhdl-parse_psl.adb b/src/vhdl/vhdl-parse_psl.adb index e456514bf..3d6d7101e 100644 --- a/src/vhdl/vhdl-parse_psl.adb +++ b/src/vhdl/vhdl-parse_psl.adb @@ -48,12 +48,18 @@ package body Vhdl.Parse_Psl is function Parse_Number return Node is + V : Int64; Res : Node; begin if Current_Token = Tok_Integer then Res := Create_Node_Loc (N_Number); -- FIXME: handle overflow. - Set_Value (Res, Uns32 (Current_Iir_Int64)); + V := Current_Iir_Int64; + if V > Int64 (Uns32'Last) then + Error_Msg_Parse ("number if too large"); + V := Int64 (Uns32'Last); + end if; + Set_Value (Res, Uns32 (V)); Scan; return Res; elsif Current_Token = Tok_Inf then -- cgit v1.2.3