diff mbox

[Ada] don't overflow version string max length

Message ID or1v63i73h.fsf@livre.localdomain
State New
Headers show

Commit Message

Alexandre Oliva Nov. 30, 2010, 7:49 a.m. UTC
I got stage2 errors compiling ada/b_gnatb.c on x86_64-linux-gnu, because
it contained garbage at the end of __gnat_version.

It turned out that the full git version below exceeded the 64 bytes
reserved for the version string:

GNAT Version: 4.6.0 20101130 (experimental) [remotes/trunk revision a20ee7a:f6b2e47:00881f33e939f70ace98eaf6e9a65735dd378ba3]

The revision got corrupted as we attempted to copy more than 64 bytes
from the C string to the Ada string, writing past the end of the
allocated range, or some such (I didn't investigate the gory details of
when the garbage made to the version string printed by gnatbind)

This patch bumps up the maximum version length, to account for the
possibility of longer branch names, and truncates the copying at the
reserved length.

Regstrapping now (already past the earlier build error, and the version
string looks good).  Ok to install?

Comments

Arnaud Charlet Nov. 30, 2010, 8:19 a.m. UTC | #1
> This patch bumps up the maximum version length, to account for the
> possibility of longer branch names, and truncates the copying at the
> reserved length.
> 
> Regstrapping now (already past the earlier build error, and the version
> string looks good).  Ok to install?

The gnatvsn.adb change certainly is fine.

I'm not very happy with bumping Ver_Len_Max again, but I guess this is OK
to commit.

> for  gcc/ada/ChangeLog
> from  Alexandre Oliva  <aoliva@redhat.com>
> 
> 	* gnatvsn.adb (Gnat_Version_String): Don't overrun Ver_Len_Max.
> 	* gnatvsn.ads (Ver_Len_Max): Bump up to 256.
> 	* g-comver.adb (Ver_Len_Max): Likewise.
diff mbox

Patch

for  gcc/ada/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* gnatvsn.adb (Gnat_Version_String): Don't overrun Ver_Len_Max.
	* gnatvsn.ads (Ver_Len_Max): Bump up to 256.
	* g-comver.adb (Ver_Len_Max): Likewise.

Index: gcc/ada/g-comver.adb
===================================================================
--- gcc/ada/g-comver.adb.orig	2010-11-30 05:07:59.264876475 -0200
+++ gcc/ada/g-comver.adb	2010-11-30 05:12:39.693675937 -0200
@@ -37,7 +37,7 @@ 
 
 package body GNAT.Compiler_Version is
 
-   Ver_Len_Max : constant := 64;
+   Ver_Len_Max : constant := 256;
    --  This is logically a reference to Gnatvsn.Ver_Len_Max but we cannot
    --  import this directly since run-time units cannot WITH compiler units.
 
Index: gcc/ada/gnatvsn.adb
===================================================================
--- gcc/ada/gnatvsn.adb.orig	2010-11-30 05:07:36.922608256 -0200
+++ gcc/ada/gnatvsn.adb	2010-11-30 05:10:54.833120167 -0200
@@ -74,6 +74,8 @@  package body Gnatvsn is
 
          S (Pos + 1) := Version_String (Pos);
          Pos := Pos + 1;
+
+         exit when Pos = Ver_Len_Max;
       end loop;
 
       return S (1 .. Pos);
Index: gcc/ada/gnatvsn.ads
===================================================================
--- gcc/ada/gnatvsn.ads.orig	2010-11-30 05:07:40.890478394 -0200
+++ gcc/ada/gnatvsn.ads	2010-11-30 05:12:25.830131950 -0200
@@ -70,7 +70,7 @@  package Gnatvsn is
    --  Return the name of the Copyright holder to be displayed by the different
    --  GNAT tools when switch --version is used.
 
-   Ver_Len_Max : constant := 64;
+   Ver_Len_Max : constant := 256;
    --  Longest possible length for Gnat_Version_String in this or any
    --  other version of GNAT. This is used by the binder to establish
    --  space to store any possible version string value for checks. This