This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA/Ada] guard against a malloc failure


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?

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;
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]