[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 <miranda@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).
From-SVN: r274654