From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4914 invoked by alias); 30 Dec 2017 00:51: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 4619 invoked by uid 89); 30 Dec 2017 00:51:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=exploits, H*r:112 X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 30 Dec 2017 00:51:10 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id vBU0p3WM020429 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 29 Dec 2017 19:51:08 -0500 Received: by simark.ca (Postfix, from userid 112) id C46361E5A6; Fri, 29 Dec 2017 19:51:03 -0500 (EST) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 894381E02D; Fri, 29 Dec 2017 19:50:52 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 30 Dec 2017 00:51:00 -0000 From: Simon Marchi To: Ruslan Kabatsayev Cc: gdb-patches@sourceware.org Subject: Re: [PATCH][RFC] Avoid indexing std::vector past the end In-Reply-To: <1514476903-5206-1-git-send-email-b7.10110111@gmail.com> References: <1514476903-5206-1-git-send-email-b7.10110111@gmail.com> Message-ID: <608baf012f787e3b74445e3ef9062b93@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.2 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 30 Dec 2017 00:51:03 +0000 X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00520.txt.bz2 On 2017-12-28 11:01, Ruslan Kabatsayev wrote: > Hello all, > > On my system I have added some asserts into GCC's stl_vector.h, which > check for > various mistakes like out of bounds access, call to std::vector::front > on empty > vector etc. to debug my own projects. After I built GDB with such > modifications, I've noticed that in some cases it accesses some vectors > out of > bound, namely element one past the end. Effectively the code is > something like > `auto*p=&someVector[someVector.size()];`, which, although may seem > legitimate > on the first glance since it simply takes address, is still Undefined > Behavior > according to the C++ Standard (see e.g. [1] and links in that page). > > So I wonder whether GDB deliberately exploits undefined behavior here > knowing > that GCC might give(?) some guarantee that this will always work as > intended, > or it's simply a mistake, and my patch would be OK. > > [1]: https://stackoverflow.com/a/27069592/673852 > > Regards, > Ruslan Hi Ruslan, Thanks for finding and reporting this. We certainly don't want to rely on any compiler-specific undefined behavior, this is a mistake. The patch looks good to me, it's just missing a ChangeLog entry. Simon