From: Siddhesh Poyarekar <siddhesh@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] Replace unsafe alloca for baseclass type
Date: Wed, 04 Jul 2012 10:34:00 -0000 [thread overview]
Message-ID: <20120704160423.1e7107a7@spoyarek> (raw)
[-- 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
{
next reply other threads:[~2012-07-04 10:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-04 10:34 Siddhesh Poyarekar [this message]
2012-07-05 13:57 ` Jan Kratochvil
2012-07-06 5:39 ` Siddhesh Poyarekar
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=20120704160423.1e7107a7@spoyarek \
--to=siddhesh@redhat.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