From patchwork Tue Nov 30 07:49:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 73579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A2CF11007D1 for ; Tue, 30 Nov 2010 18:50:27 +1100 (EST) Received: (qmail 26893 invoked by alias); 30 Nov 2010 07:50:22 -0000 Received: (qmail 26883 invoked by uid 22791); 30 Nov 2010 07:50:20 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 30 Nov 2010 07:50:15 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAU7nnJv019919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 30 Nov 2010 02:49:49 -0500 Received: from freie.oliva.athome.lsd.ic.unicamp.br (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oAU7nlRv009686 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 30 Nov 2010 02:49:48 -0500 Received: from livre.localdomain (livre-to-gw.oliva.athome.lsd.ic.unicamp.br [172.31.160.19]) by freie.oliva.athome.lsd.ic.unicamp.br (8.14.4/8.14.4) with ESMTP id oAU7ngpi026373; Tue, 30 Nov 2010 05:49:42 -0200 Received: from livre.localdomain (aoliva@localhost [127.0.0.1]) by livre.localdomain (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id oAU7neqR011007; Tue, 30 Nov 2010 05:49:40 -0200 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id oAU7nd5d011005; Tue, 30 Nov 2010 05:49:39 -0200 From: Alexandre Oliva To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [Ada] don't overflow version string max length Date: Tue, 30 Nov 2010 05:49:38 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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? for gcc/ada/ChangeLog from Alexandre Oliva * 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