From patchwork Tue Feb 12 08:36:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 1040444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495917-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eg8WM/Ev"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43zGGp3QPQz9s4Z for ; Tue, 12 Feb 2019 19:36:47 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=C1VM1Jg0/1ogKfjREo69S8nDpJgQ1WOO4M6KBf8F5zb6QvCZG0 3oXUl9Rt0pbkHpG3IRwsdVbZggge4nZ6jW8yoEAXSnJ9ljJDGbcluYN6l81PZh9U ZjU1QzSr3O0r5yfvL4PhXJO9oshql+tgxoFx5j+/YZNkGCK1zqT2yHLQc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=dS/eNBLr/9G4bCQdoDaIXaqHk0g=; b=eg8WM/Ev1pZRqW712p6N 4yR2sADbimgeAFKVsftkSGhBmKmkhr6u1GxMaF0uAOH6TCL7FeB2usa0QSHtcPcK SYyHKvoWsQoeCQDb1eAWQDfupSXoqVmtHKiD4NTPRoKw6Sl/M+5e2l3vdzPGL7ww zXA19g/wQCxhWjwEl2SVGeE= Received: (qmail 28112 invoked by alias); 12 Feb 2019 08:36:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 28076 invoked by uid 89); 12 Feb 2019 08:36:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1399 X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Feb 2019 08:36:39 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 85B3AAF17; Tue, 12 Feb 2019 08:36:37 +0000 (UTC) Date: Tue, 12 Feb 2019 09:36:55 +0100 From: Tom de Vries To: gcc-patches@gcc.gnu.org Cc: Ian Lance Taylor Subject: [PATCH][libbacktrace] Handle bsearch with NULL base in dwarf_lookup_pc Message-ID: <20190212083649.GA14912@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi, The call to bsearch in dwarf_lookup_pc can have NULL as base argument when the nmemb argument is 0. The base argument is required to be pointing to the initial member of an array of nmemb objects. It is not specified what constitutes a valid pointer to an array of 0 objects, but glibc declares base with attribute non-null, so the NULL will trigger a sanitizer runtime error. Fix this by only calling bsearch if nmemb != 0. OK for trunk? Thanks, - Tom [libbacktrace] Handle bsearch with NULL base in dwarf_lookup_pc 2019-02-12 Tom de Vries PR libbacktrace/81983 * dwarf.c (dwarf_lookup_pc): Don't call bsearch if nmemb == 0. --- libbacktrace/dwarf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c index d7dacf3ef32..f338489fe44 100644 --- a/libbacktrace/dwarf.c +++ b/libbacktrace/dwarf.c @@ -2821,8 +2821,10 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata, *found = 1; /* Find an address range that includes PC. */ - entry = bsearch (&pc, ddata->addrs, ddata->addrs_count, - sizeof (struct unit_addrs), unit_addrs_search); + entry = (ddata->addrs_count == 0 + ? NULL + : bsearch (&pc, ddata->addrs, ddata->addrs_count, + sizeof (struct unit_addrs), unit_addrs_search)); if (entry == NULL) {