From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11921 invoked by alias); 22 Oct 2009 11:09:28 -0000 Received: (qmail 11913 invoked by uid 22791); 22 Oct 2009 11:09:27 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Oct 2009 11:09:23 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9MB9DfN021419; Thu, 22 Oct 2009 07:09:13 -0400 Received: from hase.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9MB9BCh030195; Thu, 22 Oct 2009 07:09:12 -0400 From: Andreas Schwab To: Pedro Alves Cc: gdb-patches@sourceware.org, Paul Pluzhnikov , Jan Kratochvil Subject: Re: [patch] Fix for PR gdb/10819 References: <8ac60eac0910212148w24f44d53xfa6bedd7e12b41d1@mail.gmail.com> <20091022054758.GA15116@host0.dyn.jankratochvil.net> <8ac60eac0910212314h3517ff9btcad84f8d0978bddb@mail.gmail.com> <200910221142.55021.pedro@codesourcery.com> X-Yow: PEGGY FLEMING is stealing BASKET BALLS to feed the babies in VERMONT. Date: Thu, 22 Oct 2009 11:09:00 -0000 In-Reply-To: <200910221142.55021.pedro@codesourcery.com> (Pedro Alves's message of "Thu, 22 Oct 2009 11:42:54 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-10/txt/msg00517.txt.bz2 Pedro Alves 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."