From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95598 invoked by alias); 2 May 2016 16:40:12 -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 95585 invoked by uid 89); 2 May 2016 16:40:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=HReply-to:D*org, HX-HELO:eggs.gnu.org, Hx-spam-relays-external:208.118.235.92, H*RU:208.118.235.92 X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 02 May 2016 16:40:05 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axGt0-0001kq-Dj for gdb-patches@sourceware.org; Mon, 02 May 2016 12:40:00 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axGt0-0001kG-AB; Mon, 02 May 2016 12:39:54 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3422 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1axGsu-0005RD-8e; Mon, 02 May 2016 12:39:48 -0400 Date: Mon, 02 May 2016 16:40:00 -0000 Message-Id: <83wpncl8h4.fsf@gnu.org> From: Eli Zaretskii To: Pedro Alves CC: gdb-patches@sourceware.org In-reply-to: <62c5fd08-c7b5-37e2-e364-381ae8377c03@redhat.com> (message from Pedro Alves on Mon, 2 May 2016 12:50:05 +0100) Subject: Re: Off-by-one error in windows-nat.c causes abort at startup Reply-to: Eli Zaretskii References: <83bn4rpd6m.fsf@gnu.org> <62c5fd08-c7b5-37e2-e364-381ae8377c03@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00012.txt.bz2 > From: Pedro Alves > Date: Mon, 2 May 2016 12:50:05 +0100 > > On 04/30/2016 12:07 PM, Eli Zaretskii wrote: > > > Luckily, I still had GDB 7.5, which did work. Using it, I found the > > off-by-one gotcha below (".gdbinit" is one character longer than > > "gdb.ini"). I guess no one tested this feature when we switched from > > using snprintf to xsnprintf... > > Sounds like gdb would corrupt memory before we switched to xsnprintf > then. I'd say the problem is that the feature was added without a > corresponding test case. > > > OK to commit (with a suitable ChangeLog entry, of course)? > > Sure. Thanks, pushed. > > --- 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?