From: Jerome Guitton <guitton@adacore.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA/Ada] guard against a malloc failure
Date: Fri, 12 Dec 2008 15:58:00 -0000 [thread overview]
Message-ID: <20081212155749.GA18970@adacore.com> (raw)
In-Reply-To: <20081209095142.GL3823@adacore.com>
[-- Attachment #1: Type: text/plain, Size: 978 bytes --]
Joel Brobecker (brobecker@adacore.com):
> > 2008-11-27 Jerome Guitton <guitton@adacore.com>
> >
> > * ada-lang.c (ada_template_to_fixed_record_type_1): Check size
> > of type to guard against a crash.
>
> Jerome and I just discussed this patch today, and we think we may
> have a better solution. Standby...
Right. It is possible to rewrite ada_template_to_fixed_record_type_1
to avoid the crash; the discriminant value is allocated using the type
being built; the crash may happen when a bogus dynamic field is
included to this partial type. The trick is to allocate the value
before any of these dynamic fields is added to the partial type. When
we encounter a dynamic field, all the discriminant fields have already
been added, so it should be fine.
Here is the new patch, tested on linux. OK to apply?
2008-12-12 Jerome Guitton <guitton@adacore.com>
* ada-lang.c (ada_template_to_fixed_record_type_1): Allocate dval
before a dynamic field is added.
[-- Attachment #2: ada-lang.c.diff --]
[-- Type: text/x-diff, Size: 1883 bytes --]
--- ada-lang.c.prev 2008-12-12 12:49:31.000000000 +0100
+++ ada-lang.c 2008-12-12 12:54:17.000000000 +0100
@@ -6831,7 +6831,7 @@ ada_template_to_fixed_record_type_1 (str
int keep_dynamic_fields)
{
struct value *mark = value_mark ();
- struct value *dval;
+ struct value *dval = dval0;
struct type *rtype;
int nfields, bit_len;
int variant_field;
@@ -6882,10 +6882,17 @@ ada_template_to_fixed_record_type_1 (str
}
else if (is_dynamic_field (type, f))
{
- if (dval0 == NULL)
+ /* If dval is NULL, build it using the record type that we are
+ initializing. This takes advantage of the fact that the
+ discrimant fields should appear before any dynamic field;
+ so, at this point, the discriminant fields have already been
+ added to rtype. This property also assure that this dval will
+ be valid for the rest of the computation, no need to re-allocate
+ a new one for every dynamic field. Finally, as the value is
+ allocated before any dynamic field has been added to the type,
+ we do not have to check its size before the allocation. */
+ if (dval == NULL)
dval = value_from_contents_and_address (rtype, valaddr, address);
- else
- dval = dval0;
/* Get the fixed type of the field. Note that, in this case, we
do not want to get the real type out of the tag: if the current
@@ -6931,10 +6938,8 @@ ada_template_to_fixed_record_type_1 (str
off = TYPE_FIELD_BITPOS (rtype, variant_field);
- if (dval0 == NULL)
+ if (dval == NULL)
dval = value_from_contents_and_address (rtype, valaddr, address);
- else
- dval = dval0;
branch_type =
to_fixed_variant_branch_type
next prev parent reply other threads:[~2008-12-12 15:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20081127145701.GB3835@adacore.com>
2008-12-09 9:52 ` Joel Brobecker
2008-12-12 15:58 ` Jerome Guitton [this message]
2008-12-12 18:40 ` Jerome Guitton
2009-02-04 16:10 ` Jerome Guitton
2009-02-04 16:20 ` Joel Brobecker
2009-02-04 17:47 ` Jerome Guitton
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=20081212155749.GA18970@adacore.com \
--to=guitton@adacore.com \
--cc=brobecker@adacore.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