aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire Dross <dross@adacore.com>2019-07-11 08:02:44 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-11 08:02:44 +0000
commit1048a1839fde97a1bd790b002dad8b79e172724f (patch)
tree4389d46dc27fe6b85491206c7fc8ab09afbec5b1
parent9d80f439131664ba852db64a6d5ac80a4d4e6f2e (diff)
downloadgcc-1048a1839fde97a1bd790b002dad8b79e172724f.zip
gcc-1048a1839fde97a1bd790b002dad8b79e172724f.tar.gz
gcc-1048a1839fde97a1bd790b002dad8b79e172724f.tar.bz2
[Ada] Memory corruption when using formal hashed sets or maps
Add a check to avoid causing a buffer overflow when the map is empty 2019-07-11 Claire Dross <dross@adacore.com> gcc/ada/ * libgnat/a-cfhama.adb, libgnat/a-cfhase.adb (Free): Do not reset the Has_Element flag if no element is freed. From-SVN: r273397
-rw-r--r--gcc/ada/ChangeLog5
-rw-r--r--gcc/ada/libgnat/a-cfhama.adb7
-rw-r--r--gcc/ada/libgnat/a-cfhase.adb7
3 files changed, 15 insertions, 4 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index a38990f..2f8ad77 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,8 @@
+2019-07-11 Claire Dross <dross@adacore.com>
+
+ * libgnat/a-cfhama.adb, libgnat/a-cfhase.adb (Free): Do not
+ reset the Has_Element flag if no element is freed.
+
2019-07-11 Arnaud Charlet <charlet@adacore.com>
* errno.c: Remove obsolete support for MaRTE OS.
diff --git a/gcc/ada/libgnat/a-cfhama.adb b/gcc/ada/libgnat/a-cfhama.adb
index 2cdde01..580ca12 100644
--- a/gcc/ada/libgnat/a-cfhama.adb
+++ b/gcc/ada/libgnat/a-cfhama.adb
@@ -509,8 +509,11 @@ is
procedure Free (HT : in out Map; X : Count_Type) is
begin
- HT.Nodes (X).Has_Element := False;
- HT_Ops.Free (HT, X);
+ if X /= 0 then
+ pragma Assert (X <= HT.Capacity);
+ HT.Nodes (X).Has_Element := False;
+ HT_Ops.Free (HT, X);
+ end if;
end Free;
----------------------
diff --git a/gcc/ada/libgnat/a-cfhase.adb b/gcc/ada/libgnat/a-cfhase.adb
index ae8ae12..8cc220c 100644
--- a/gcc/ada/libgnat/a-cfhase.adb
+++ b/gcc/ada/libgnat/a-cfhase.adb
@@ -760,8 +760,11 @@ is
procedure Free (HT : in out Set; X : Count_Type) is
begin
- HT.Nodes (X).Has_Element := False;
- HT_Ops.Free (HT, X);
+ if X /= 0 then
+ pragma Assert (X <= HT.Capacity);
+ HT.Nodes (X).Has_Element := False;
+ HT_Ops.Free (HT, X);
+ end if;
end Free;
----------------------