This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix for PR gdb/10819


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]