From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Paul Pluzhnikov <ppluzhnikov@google.com>,
Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: Re: [patch] Fix for PR gdb/10819
Date: Thu, 22 Oct 2009 10:43:00 -0000 [thread overview]
Message-ID: <200910221142.55021.pedro@codesourcery.com> (raw)
In-Reply-To: <8ac60eac0910212314h3517ff9btcad84f8d0978bddb@mail.gmail.com>
On Thursday 22 October 2009 07:14:21, Paul Pluzhnikov wrote:
> Comment added.
> + if (cie_table->num_entries == 0)
> + {
> + /* On Solaris 8 bsearch may call comparison function even when given
> + an empty table. As a work around, don't call bsearch under these
> + conditions. */
> + return NULL;
> + }
>Apparently calling bsearch on a table with zero elements is unsafe on Solaris
>8.
FTR, so that this is archived, see:
http://cvs.opensolaris.org/source/xref/pef/phase_I/usr/src/lib/libbc/libc/gen/common/bsearch.c
43 int two_width = width + width;
44 POINTER last = base + width * (nel - 1); /* Last element in table */
45
46 while (last >= base) {
The issue happens because you're passing a NULL BASE (your ENTRIES), so
LAST wraps around, and the while loop enters. That bsearch assumes
BASE is a pointer into a valid object, which seems valid given
that BASE should point at an array of NEL objects. You don't have
a table with zero elements, you have no table at all. Note that
the solaris man page doesn't explicitly specify that when NEL is 0, the
compare function should not be called, no matter what. opengroup.org
does, but that probably post dates the original bsearch appearences.
This seems to have been considered in more recent sources:
http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/common/util/bsearch.c
It is quite possible that other unix hosts have the same
valid-object assumption, if not by chance, because it's quite
possible that they've inherited the exact same bsearch.c
implementation. I see that netbsd's implementation even
asserts (in devel builds only it seems) that base is not null.
There's another bsearch call in dwarf2-frame.c and another one
in objfiles.c (all recent and yours, it seems :-)). Do they need
attention to the base==NULL or number-elements==0 case as well?
-
Pedro Alves
next prev parent reply other threads:[~2009-10-22 10:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-22 4:48 Paul Pluzhnikov
2009-10-22 5:48 ` Jan Kratochvil
2009-10-22 6:14 ` Paul Pluzhnikov
2009-10-22 10:43 ` Pedro Alves [this message]
2009-10-22 11:09 ` Andreas Schwab
2009-10-22 15:34 ` Paul Pluzhnikov
2009-10-22 16:30 ` Paul Pluzhnikov
2009-10-22 17:44 ` Tom Tromey
2009-10-22 18:31 ` Paul Pluzhnikov
2009-10-22 20:13 ` Tom Tromey
2009-10-22 20:46 ` Paul Pluzhnikov
2009-10-22 18:11 ` Pedro Alves
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=200910221142.55021.pedro@codesourcery.com \
--to=pedro@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=ppluzhnikov@google.com \
/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