Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@redhat.com>
To: Pedro Alves <pedro@codesourcery.com>
Cc: gdb-patches@sourceware.org,
	Paul Pluzhnikov <ppluzhnikov@google.com>,
	        Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: Re: [patch] Fix for PR gdb/10819
Date: Thu, 22 Oct 2009 11:09:00 -0000	[thread overview]
Message-ID: <m38wf3it2g.fsf@hase.home> (raw)
In-Reply-To: <200910221142.55021.pedro@codesourcery.com> (Pedro Alves's 	message of "Thu, 22 Oct 2009 11:42:54 +0100")

Pedro Alves <pedro@codesourcery.com> writes:

> 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.

Note that this is what the C standard requires.  Even if the number of
elements is zero all pointer arguments must still be valid.

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."


  reply	other threads:[~2009-10-22 11:09 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
2009-10-22 11:09       ` Andreas Schwab [this message]
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=m38wf3it2g.fsf@hase.home \
    --to=schwab@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=pedro@codesourcery.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