From c4ca0af40b65c91c99036d339c93ed938b3f0cc2 Mon Sep 17 00:00:00 2001 From: Nicolas Roche Date: Mon, 11 Jun 2018 09:16:32 +0000 Subject: [PATCH] [Ada] Avoid a stack overflow in 'Value for invalid long strings 2018-06-11 Nicolas Roche gcc/ada/ * libgnat/s-valuti.adb (Bad_Value): Ensure that we do not generate a stack overflow while raising a constraint error. From-SVN: r261396 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/libgnat/s-valuti.adb | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index e2191200c1e..5b13f28f0db 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-06-11 Nicolas Roche + + * libgnat/s-valuti.adb (Bad_Value): Ensure that we do not generate a + stack overflow while raising a constraint error. + 2018-06-11 Eric Botcazou * repinfo.ads (Rep_Value): Use a single line. diff --git a/gcc/ada/libgnat/s-valuti.adb b/gcc/ada/libgnat/s-valuti.adb index 8071fcabf36..3070f312257 100644 --- a/gcc/ada/libgnat/s-valuti.adb +++ b/gcc/ada/libgnat/s-valuti.adb @@ -39,7 +39,15 @@ package body System.Val_Util is procedure Bad_Value (S : String) is begin - raise Constraint_Error with "bad input for 'Value: """ & S & '"'; + -- Bad_Value might be called with very long strings allocated on the + -- heap. Limit the size of the message so that we avoid creating a + -- Storage_Error during error handling. + if S'Length > 127 then + raise Constraint_Error with "bad input for 'Value: """ + & S (S'First .. S'First + 127) & "..."""; + else + raise Constraint_Error with "bad input for 'Value: """ & S & '"'; + end if; end Bad_Value; ---------------------- -- 2.30.2