From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11909 invoked by alias); 12 Jul 2013 09:18:19 -0000 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 Received: (qmail 11845 invoked by uid 89); 12 Jul 2013 09:18:16 -0000 X-Spam-SWARE-Status: No, score=-4.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_MED,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mms1.broadcom.com (HELO mms1.broadcom.com) (216.31.210.17) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 12 Jul 2013 09:18:15 +0000 Received: from [10.9.208.57] by mms1.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.5)); Fri, 12 Jul 2013 02:14:15 -0700 X-Server-Uuid: 06151B78-6688-425E-9DE2-57CB27892261 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.1.438.0; Fri, 12 Jul 2013 02:18:00 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.1.438.0; Fri, 12 Jul 2013 02:18:00 -0700 Received: from [10.177.73.66] (unknown [10.177.73.66]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id F336FF2D72; Fri, 12 Jul 2013 02:17:59 -0700 (PDT) Message-ID: <51DFC9C6.2060806@broadcom.com> Date: Fri, 12 Jul 2013 09:18:00 -0000 From: "Andrew Burgess" User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: gdb-patches@sourceware.org cc: "Andreas Schwab" , Paul_Koning@Dell.com Subject: Re: [PATCH] Don't call strchr with the NULL character. References: <51DEDA0E.8020809@broadcom.com> In-Reply-To: <51DEDA0E.8020809@broadcom.com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-07/txt/msg00331.txt.bz2 On 11/07/2013 5:15 PM, Andrew Burgess wrote: > In the printf code we call strchr without guarding against the > case where the second parameter is NULL. > > My local manpage for strchr doesn't say what happens in this case, > but this file: src/libiberty/strchr.c > suggests the results are undefined, and indeed, the answer I see is > not NULL (which is what I might have hoped for). Thanks to both Andreas and Paul for pointing out more up to date manual pages that explain the behaviour is NOT undefined at all. That said, my patch (I believe) fixes gdb given the /current/ behaviour, which I thought was undefined, but is in fact well defined. Either way I believe this patch is required. Here's an example from before my patch: while (strchr ("0-+ #", *f)) { if (*f == '#') seen_hash = 1; else if (*f == '0') seen_zero = 1; else if (*f == ' ') seen_space = 1; else if (*f == '+') seen_plus = 1; f++; } If *f is the end of string NULL character then the loop above will run off the end of the string. Thanks, Andrew