From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37420 invoked by alias); 2 May 2016 18:01:16 -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 37407 invoked by uid 89); 2 May 2016 18:01:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2526 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 02 May 2016 18:01:14 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E790C04B30B; Mon, 2 May 2016 18:01:13 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u42I1BC6004001; Mon, 2 May 2016 14:01:12 -0400 Subject: Re: Off-by-one error in windows-nat.c causes abort at startup To: Eli Zaretskii References: <83bn4rpd6m.fsf@gnu.org> <62c5fd08-c7b5-37e2-e364-381ae8377c03@redhat.com> <83wpncl8h4.fsf@gnu.org> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <59183932-8ea1-7c2c-d4e2-b1567ede1260@redhat.com> Date: Mon, 02 May 2016 18:01:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <83wpncl8h4.fsf@gnu.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-05/txt/msg00017.txt.bz2 On 05/02/2016 05:39 PM, Eli Zaretskii wrote: >> From: Pedro Alves >>> --- gdb/windows-nat.c~ 2016-02-10 05:19:39.000000000 +0200 >>> +++ gdb/windows-nat.c 2016-04-30 11:57:08.500000000 +0300 >>> @@ -2711,9 +2711,9 @@ _initialize_check_for_gdb_ini (void) >>> if (access (oldini, 0) == 0) >>> { >>> int len = strlen (oldini); >>> - char *newini = (char *) alloca (len + 1); >>> + char *newini = (char *) alloca (len + 2); >>> >>> - xsnprintf (newini, len + 1, "%.*s.gdbinit", >>> + xsnprintf (newini, len + 2, "%.*s.gdbinit", >>> (int) (len - (sizeof ("gdb.ini") - 1)), oldini); >>> warning (_("obsolete '%s' found. Rename to '%s'."), oldini, newini); >> >> (I suspect this whole function could be rewritten in a clearer form...) > > Like not use xsnprintf at all, and instead use strcpy/strcat, perhaps? > Yeah, something like this (untested). >From 33738f6c5bf7f76d6cb6853aecf880c5570f7d74 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 2 May 2016 18:57:50 +0100 Subject: [PATCH] Rewrite/simplify old gdb.ini warning --- gdb/windows-nat.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 2e8a777..161e887 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2694,27 +2694,28 @@ void _initialize_check_for_gdb_ini (void) { char *homedir; + if (inhibit_gdbinit) return; homedir = getenv ("HOME"); - if (homedir) + if (homedir != NULL) { - char *p; - char *oldini = (char *) alloca (strlen (homedir) + - sizeof ("gdb.ini") + 1); - strcpy (oldini, homedir); - p = strchr (oldini, '\0'); - if (p > oldini && !IS_DIR_SEPARATOR (p[-1])) - *p++ = '/'; - strcpy (p, "gdb.ini"); + size_t homedir_len = strlen (homedir); + char *oldini; + + while (homedir_len > 0 && IS_DIR_SEPARATOR (homedir[homedir_len - 1])) + homedir_len--; + + oldini = (char *) alloca (homedir_len + sizeof ("/gdb.ini")); + memcpy (oldini, homedir, homedir_len); + strcpy (oldini + homedir_len, "/gdb.ini"); if (access (oldini, 0) == 0) { - int len = strlen (oldini); - char *newini = (char *) alloca (len + 2); + char *newini = (char *) alloca (homedir_len + sizeof ("/.gdbinit")); - xsnprintf (newini, len + 2, "%.*s.gdbinit", - (int) (len - (sizeof ("gdb.ini") - 1)), oldini); + memcpy (newini, homedir, homedir_len); + strcpy (newini + homedir_len, "/.gdbinit"); warning (_("obsolete '%s' found. Rename to '%s'."), oldini, newini); } } -- 2.5.5