https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65696

--- Comment #3 from pmderodat at gcc dot gnu.org ---
Author: pmderodat
Date: Mon Aug 19 08:36:39 2019
New Revision: 274654

URL: https://gcc.gnu.org/viewcvs?rev=274654&root=gcc&view=rev
Log:
[Ada] Buffer reading overflow in dispatch table initialization

For tagged types not defined at library level that derive from library
level tagged types the compiler may generate code to initialize their
dispatch table of predefined primitives copying from the parent type
data stored in memory after the dispatch table of the parent; that is,
at runtime the initialization of dispatch tables overflows reading the
parent dispatch table.

This problem does not affect the execution of the program since the
target dispatch table always has enough space to store the extra data,
and after such copy the compiler generates code to complete the
initialization of the dispatch table.

The following test must compile and execute without errors.

package pkg_a is
   type Root is tagged null record;
end pkg_a;

with pkg_a;
procedure main is
   type Derived is new pkg_a.Root with null record;  -- Test
begin
   null;
end main;

Command: gnatmake -q main -fsanitize=address; ./main

2019-08-19  Javier Miranda  <mira...@adacore.com>

gcc/ada/

        PR ada/65696
        * exp_atag.ads, exp_atag.adb (Build_Inherit_Predefined_Prims):
        Adding formal to specify how many predefined primitives are
        inherited from the parent type.
        * exp_disp.adb (Number_Of_Predefined_Prims): New subprogram.
        (Make_Secondary_DT): Compute the number of predefined primitives
        of all tagged types (including tagged types not defined at
        library level).  Previously we unconditionally relied on the
        Max_Predef_Prims constant value when building the dispatch
        tables of tagged types not defined at library level (thus
        consuming more memory for their dispatch tables than required).
        (Make_DT): Compute the number of predefined primitives that must
        be inherited from their parent type when building the dispatch
        tables of tagged types not defined at library level. Previously
        we unconditionally relied on the Max_Predef_Prims constant value
        when building the dispatch tables of tagged types not defined at
        library level (thus copying more data than required from the
        parent type).

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/exp_atag.adb
    trunk/gcc/ada/exp_atag.ads
    trunk/gcc/ada/exp_disp.adb

Reply via email to