Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jerome Guitton <guitton@adacore.com>
To: gdb-patches@sourceware.org
Subject: Re: [RFA/Ada] guard against a malloc failure
Date: Wed, 04 Feb 2009 16:10:00 -0000	[thread overview]
Message-ID: <20090204160949.GA35460@adacore.com> (raw)
In-Reply-To: <20081127145701.GB3835@adacore.com>

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]


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  <guitton@adacore.com>

	* ada-lang.c (ada_template_to_fixed_record_type_1): Check size
	of type to guard against a crash.


OK to apply?


[-- Attachment #2: check_size.diff --]
[-- Type: text/x-diff, Size: 943 bytes --]

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;
 

  parent reply	other threads:[~2009-02-04 16:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20081127145701.GB3835@adacore.com>
2008-12-09  9:52 ` Joel Brobecker
2008-12-12 15:58   ` Jerome Guitton
2008-12-12 18:40     ` Jerome Guitton
2009-02-04 16:10 ` Jerome Guitton [this message]
2009-02-04 16:20   ` Joel Brobecker
2009-02-04 17:47     ` Jerome Guitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090204160949.GA35460@adacore.com \
    --to=guitton@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox