aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNicolas Roche <roche@adacore.com>2018-06-11 09:16:32 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-06-11 09:16:32 +0000
commitc4ca0af40b65c91c99036d339c93ed938b3f0cc2 (patch)
treec4419ab3f9f05ca8527c435aa4d4dc3d5c0c98fd /gcc
parent972d29849fc76fea06110ca5b3b3fbce1f9e1fd2 (diff)
downloadgcc-c4ca0af40b65c91c99036d339c93ed938b3f0cc2.zip
gcc-c4ca0af40b65c91c99036d339c93ed938b3f0cc2.tar.gz
gcc-c4ca0af40b65c91c99036d339c93ed938b3f0cc2.tar.bz2
[Ada] Avoid a stack overflow in 'Value for invalid long strings
2018-06-11 Nicolas Roche <roche@adacore.com> 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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog5
-rw-r--r--gcc/ada/libgnat/s-valuti.adb10
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index e219120..5b13f28 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,8 @@
+2018-06-11 Nicolas Roche <roche@adacore.com>
+
+ * 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 <ebotcazou@adacore.com>
* 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 8071fca..3070f31 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;
----------------------