From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9329 invoked by alias); 4 Feb 2009 16:10:01 -0000 Received: (qmail 9317 invoked by uid 22791); 4 Feb 2009 16:09:58 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 04 Feb 2009 16:09:53 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BCB6929001F for ; Wed, 4 Feb 2009 17:09:50 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kCW4FJfV-tyN for ; Wed, 4 Feb 2009 17:09:49 +0100 (CET) Received: from province.act-europe.fr (province.act-europe.fr [10.10.0.214]) by mel.act-europe.fr (Postfix) with ESMTP id B3CA429000D for ; Wed, 4 Feb 2009 17:09:49 +0100 (CET) Received: by province.act-europe.fr (Postfix, from userid 560) id A5F62165CBB; Wed, 4 Feb 2009 17:09:49 +0100 (CET) Date: Wed, 04 Feb 2009 16:10:00 -0000 From: Jerome Guitton To: gdb-patches@sourceware.org Subject: Re: [RFA/Ada] guard against a malloc failure Message-ID: <20090204160949.GA35460@adacore.com> References: <20081127145701.GB3835@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="EuxKj2iCbKjpUGkD" Content-Disposition: inline In-Reply-To: <20081127145701.GB3835@adacore.com> User-Agent: Mutt/1.5.17 (2007-11-01) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-02/txt/msg00096.txt.bz2 --EuxKj2iCbKjpUGkD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1105 Jerome Guitton (guitton@adacore.com): > First fix for the test failure mentioned in: > http://sourceware.org/ml/gdb-patches/2008-11/msg00718.html > > ada_template_to_fixed_record_type_1 builds a fixed-size record type > from the run-time values of its discriminants. If the record contains > dynamic field, and if its discriminants are not initialized, the type > may end up to be unreasonably big and GDB may fail to allocate a value > of this type. This patch adds a check for such a case. Summary of this thread: I first submitted a patch to guard against the malloc failure, and then I thought that there was a way to change the algorithm in order to avoid this check_size guard. Unfortunately, it appears that there are cases that my new algorithm that does not handle. So back to the original patch. The new call to check_size is not such a big deal after all; the built type size is checked at the end of the function anyway. 2008-02-04 Jerome Guitton * ada-lang.c (ada_template_to_fixed_record_type_1): Check size of type to guard against a crash. OK to apply? --EuxKj2iCbKjpUGkD Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="check_size.diff" Content-length: 943 Index: ada-lang.c =================================================================== RCS file: /cvs/src/src/gdb/ada-lang.c,v retrieving revision 1.187 diff -u -p -r1.187 ada-lang.c --- ada-lang.c 13 Jan 2009 10:34:30 -0000 1.187 +++ ada-lang.c 4 Feb 2009 16:08:15 -0000 @@ -6877,7 +6877,15 @@ ada_template_to_fixed_record_type_1 (str else if (is_dynamic_field (type, f)) { if (dval0 == NULL) - dval = value_from_contents_and_address (rtype, valaddr, address); + { + /* rtype's length is computed based on the run-time + value of discriminants. If the discriminants are not + initialized, the type size may be completely bogus and + GDB may fail to allocate a value for it. So check the + size first before creating the value. */ + check_size (rtype); + dval = value_from_contents_and_address (rtype, valaddr, address); + } else dval = dval0; --EuxKj2iCbKjpUGkD--