* [PATCH] Remove more instances of unsafe alloca
@ 2012-07-23 12:41 Siddhesh Poyarekar
2012-07-23 14:07 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Siddhesh Poyarekar @ 2012-07-23 12:41 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 593 bytes --]
Hi,
I found another couple of instances of unsafe alloca usage in gdb, both
to do with trying to allocate memory on stack for a baseclass type. The
fix is on the lines of what was done in the following changeset:
http://sourceware.org/ml/gdb-cvs/2012-07/msg00044.html
I have verified that the fix does not cause any regressions on x86_64.
OK to commit?
Regards,
Siddhesh
gdb/ChangeLog:
2012-07-23 Siddhesh Poyarekar <siddhesh@redhat.com>
* p-valprint.c (pascal_object_print_value): Replace potentially
unsafe alloca with xmalloc/xfree.
* valops.c (search_struct_method): Likewise.
[-- Attachment #2: alloca-cleanup.patch --]
[-- Type: text/x-patch, Size: 1929 bytes --]
? alloca-cleanup.patch
Index: gdb/p-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-valprint.c,v
retrieving revision 1.100
diff -u -r1.100 p-valprint.c
--- gdb/p-valprint.c 18 May 2012 21:02:49 -0000 1.100
+++ gdb/p-valprint.c 23 Jul 2012 12:34:37 -0000
@@ -797,8 +797,11 @@
if (boffset < 0 || boffset >= TYPE_LENGTH (type))
{
- /* FIXME (alloc): not safe is baseclass is really really big. */
- 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);
base_valaddr = buf;
if (target_read_memory (address + boffset, buf,
@@ -807,6 +810,7 @@
address = address + boffset;
thisoffset = 0;
boffset = 0;
+ do_cleanups (back_to);
}
else
base_valaddr = valaddr;
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.297
diff -u -r1.297 valops.c
--- gdb/valops.c 24 Jun 2012 07:28:10 -0000 1.297
+++ gdb/valops.c 23 Jul 2012 12:34:40 -0000
@@ -2281,8 +2281,13 @@
if (offset < 0 || offset >= TYPE_LENGTH (type))
{
- gdb_byte *tmp = alloca (TYPE_LENGTH (baseclass));
- CORE_ADDR address = value_address (*arg1p);
+ gdb_byte *tmp;
+ struct cleanup *back_to;
+ CORE_ADDR address;
+
+ tmp = xmalloc (TYPE_LENGTH (baseclass));
+ back_to = make_cleanup (xfree, tmp);
+ address = value_address (*arg1p);
if (target_read_memory (address + offset,
tmp, TYPE_LENGTH (baseclass)) != 0)
@@ -2293,6 +2298,7 @@
address + offset);
base_valaddr = value_contents_for_printing (base_val);
this_offset = 0;
+ do_cleanups (back_to);
}
else
{
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Remove more instances of unsafe alloca
2012-07-23 12:41 [PATCH] Remove more instances of unsafe alloca Siddhesh Poyarekar
@ 2012-07-23 14:07 ` Tom Tromey
2012-07-23 18:09 ` Siddhesh Poyarekar
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2012-07-23 14:07 UTC (permalink / raw)
To: Siddhesh Poyarekar; +Cc: gdb-patches
>>>>> "Siddhesh" == Siddhesh Poyarekar <siddhesh@redhat.com> writes:
Siddhesh> 2012-07-23 Siddhesh Poyarekar <siddhesh@redhat.com>
Siddhesh> * p-valprint.c (pascal_object_print_value): Replace potentially
Siddhesh> unsafe alloca with xmalloc/xfree.
Siddhesh> * valops.c (search_struct_method): Likewise.
Ok. Thanks.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Remove more instances of unsafe alloca
2012-07-23 14:07 ` Tom Tromey
@ 2012-07-23 18:09 ` Siddhesh Poyarekar
0 siblings, 0 replies; 3+ messages in thread
From: Siddhesh Poyarekar @ 2012-07-23 18:09 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Mon, 23 Jul 2012 08:07:22 -0600, Tom wrote:
> >>>>> "Siddhesh" == Siddhesh Poyarekar <siddhesh@redhat.com> writes:
>
> Siddhesh> 2012-07-23 Siddhesh Poyarekar <siddhesh@redhat.com>
> Siddhesh> * p-valprint.c (pascal_object_print_value): Replace
> Siddhesh> potentially unsafe alloca with xmalloc/xfree.
> Siddhesh> * valops.c (search_struct_method): Likewise.
>
> Ok. Thanks.
>
Committed:
http://sourceware.org/ml/gdb-cvs/2012-07/msg00182.html
Regards,
Siddhesh
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-23 18:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-23 12:41 [PATCH] Remove more instances of unsafe alloca Siddhesh Poyarekar
2012-07-23 14:07 ` Tom Tromey
2012-07-23 18:09 ` Siddhesh Poyarekar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox