]> gcc.gnu.org Git - gcc.git/commit
[Ada] Integer overflow in SS_Allocate
authorPatrick Bernardi <bernardi@adacore.com>
Thu, 11 Jan 2018 08:51:23 +0000 (08:51 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 11 Jan 2018 08:51:23 +0000 (08:51 +0000)
commit6a5e79b44f0d0d06c793ec200ef3b597b07ebc1a
tree185d602b38c3d191f86bf896a9e94a0207426bad
parent5cb78fb862e7eb963c0c6d0ce2deae5b8112858d
[Ada] Integer overflow in SS_Allocate

This patch imposes a new check and rewrites existing ones to ensure operations
involving SS_Ptr do not cause an Integer overflow. The Default_Sec_Stack_Size
function was removed in the process to simplify System.Parameter.

SS_Ptr was derived from the integer System.Parameters.Size_Type to ease the
creation of objects of type SS_Stack by the binder and imposes a maximum
secondary stack size of 2GB. In most cases, the user will not hit this limit as
they cannot specify task stack sizes of more than 2GB via the Storage_Size and
Secondary_Stack_Size pragmas. Additionally, most operating systems limit the
primary stack size to less than 2GB, with defaults under 10MB. Linux is the
rare exception where the user can unbound the primary stack.

Executing the following:
gnatmake -q overflow
./overflow

must yield:

raised STORAGE_ERROR : s-secsta.adb:140 explicit raise

--  overflow.adb:

with String_Pack;

procedure Overflow is
begin
   null;
end Overflow;

-- string_pack.ads:

package String_Pack is
   function Return_Big_String return String;
end String_Pack;

-- string_pack.adb:

with Ada.Strings.Fixed; use Ada.Strings.Fixed;

package body String_Pack is
   function Return_Big_String return String is
   begin
      return Integer'Last * "P";
   end Return_Big_String;

   S : String := Return_Big_String;

end String_Pack;

2018-01-11  Patrick Bernardi  <bernardi@adacore.com>

gcc/ada/

* libgnat/s-parame*.adb, libgnat/s-parame*.ads: Remove unneeded
Default_Sec_Stack_Size.
* libgnat/s-secsta.adb (SS_Allocate): Handle the fixed secondary stack
limit check so that the integer index does not overflow. Check the
dynamic stack allocation does not cause the secondary stack pointer to
overflow.
(SS_Info): Align colons.
(SS_Init): Cover the case when bootstraping with an old compiler that
does not set Default_SS_Size.

From-SVN: r256492
gcc/ada/ChangeLog
gcc/ada/libgnat/s-parame.adb
gcc/ada/libgnat/s-parame.ads
gcc/ada/libgnat/s-parame__ae653.ads
gcc/ada/libgnat/s-parame__hpux.ads
gcc/ada/libgnat/s-parame__rtems.adb
gcc/ada/libgnat/s-parame__vxworks.adb
gcc/ada/libgnat/s-parame__vxworks.ads
gcc/ada/libgnat/s-secsta.adb
This page took 0.19996 seconds and 5 git commands to generate.