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]

[PATCH] Replace unsafe alloca for baseclass type


Hi,

While working on a review for the bitpos patch[1], I found an unsafe
alloca in cp-valprint, which could result in a crash since the
baseclass size could get very large. Here's a patch based on Jan's
suggestion to fix this.

I have tested to verify that this does not introduce any regressions in
the testsuite on x86_64.

Regards,
Siddhesh

[1] http://sourceware.org/ml/gdb-patches/2012-06/msg00851.html


gdb/ChangeLog:

2012-07-04  Siddhesh Poyarekar  <siddhesh@redhat.com>
	    Jan Kartochvil  <jan.kratochvil@redhat.com>

	* cp-valprint.c (cp_print_value): Replace potentially unsafe
	alloca with xmalloc/xfree.
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 2e3beea..c066aa5 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -554,9 +554,11 @@ cp_print_value (struct type *type, struct type *real_type,
 	      if ((boffset + offset) < 0
 		  || (boffset + offset) >= TYPE_LENGTH (real_type))
 		{
-		  /* FIXME (alloca): unsafe if baseclass is really
-		     really large.  */
-		  gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
+		  gdb_byte *buf;
+		  struct cleanup *back_to;
+
+		  buf = xmalloc (TYPE_LENGTH (baseclass));
+		  back_to = make_cleanup (xfree, buf);
 
 		  if (target_read_memory (address + boffset, buf,
 					  TYPE_LENGTH (baseclass)) != 0)
@@ -568,6 +570,7 @@ cp_print_value (struct type *type, struct type *real_type,
 		  boffset = 0;
 		  thistype = baseclass;
 		  base_valaddr = value_contents_for_printing_const (base_val);
+		  do_cleanups (back_to);
 		}
 	      else
 		{

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