Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Replace unsafe alloca for baseclass type
@ 2012-07-04 10:34 Siddhesh Poyarekar
  2012-07-05 13:57 ` Jan Kratochvil
  0 siblings, 1 reply; 3+ messages in thread
From: Siddhesh Poyarekar @ 2012-07-04 10:34 UTC (permalink / raw)
  To: gdb-patches

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

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.

[-- Attachment #2: gdb-alloca.patch --]
[-- Type: text/x-patch, Size: 914 bytes --]

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
 		{

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Replace unsafe alloca for baseclass type
  2012-07-04 10:34 [PATCH] Replace unsafe alloca for baseclass type Siddhesh Poyarekar
@ 2012-07-05 13:57 ` Jan Kratochvil
  2012-07-06  5:39   ` Siddhesh Poyarekar
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2012-07-05 13:57 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: gdb-patches

On Wed, 04 Jul 2012 12:34:23 +0200, Siddhesh Poyarekar wrote:
> 	* cp-valprint.c (cp_print_value): Replace potentially unsafe
> 	alloca with xmalloc/xfree.

OK for check-in, after you get the CVS write access and check in your name to
the 'Write After Approval' section of gdb/MAINTAINERS.


Thanks,
Jan


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Replace unsafe alloca for baseclass type
  2012-07-05 13:57 ` Jan Kratochvil
@ 2012-07-06  5:39   ` Siddhesh Poyarekar
  0 siblings, 0 replies; 3+ messages in thread
From: Siddhesh Poyarekar @ 2012-07-06  5:39 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

On Thu, 5 Jul 2012 15:57:18 +0200, Jan wrote:

> On Wed, 04 Jul 2012 12:34:23 +0200, Siddhesh Poyarekar wrote:
> > 	* cp-valprint.c (cp_print_value): Replace potentially unsafe
> > 	alloca with xmalloc/xfree.
> 
> OK for check-in, after you get the CVS write access and check in your
> name to the 'Write After Approval' section of gdb/MAINTAINERS.
> 

Thanks, checked in:

http://sourceware.org/ml/gdb-cvs/2012-07/msg00044.html

Regards,
Siddhesh


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-06  5:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-04 10:34 [PATCH] Replace unsafe alloca for baseclass type Siddhesh Poyarekar
2012-07-05 13:57 ` Jan Kratochvil
2012-07-06  5:39   ` Siddhesh Poyarekar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox