From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117538 invoked by alias); 27 Aug 2018 19:12: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 117515 invoked by uid 89); 27 Aug 2018 19:12:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: sesbmg22.ericsson.net Received: from sesbmg22.ericsson.net (HELO sesbmg22.ericsson.net) (193.180.251.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Aug 2018 19:12:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1535397130; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9EBN15VnMr/DyQhrf1pZ2mxfP9G+zFBEsxzGPklDkvo=; b=ZDvfmXSaToZWTsCiaNZZ95FRM804zCVpu4N5dYjvJ0z4POlfec8OPVlWSLtjX1Rt IrtLbZ3gzDik8C4UxK18AvQRIg+5In1V28RSeSS/DGXE4z0UQ+cYzr7bkHsNfAyw fv/ZdWuUzNpT2B6oZ5diwKoCS6l20r6ZSxzL1R6I9iY=; Received: from ESESBMB503.ericsson.se (Unknown_Domain [153.88.183.116]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id 16.8C.21978.A0D448B5; Mon, 27 Aug 2018 21:12:10 +0200 (CEST) Received: from ESESBMB504.ericsson.se (153.88.183.171) by ESESBMB503.ericsson.se (153.88.183.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Mon, 27 Aug 2018 21:12:10 +0200 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB504.ericsson.se (153.88.183.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Mon, 27 Aug 2018 21:12:10 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vpFHqmSh26ThmNO90XqBbCyrwzqwtXaFPH9yv5I5P9c=; b=GrpCwMlY0mbNVpZO9j0tvluZLACY2OM6plsE3kTATN1ZD2aFv4T3nDmtG2YJ1a0wu7qgsCP5Kr9s+groFXWhonEX6xJKFoMmqQKregQx9sXFxjIFPAJaKY1qzHQeJ2qYZv0z2G2tgm98DiifKkAbbkrXYdzAiCOdUmo2xSl+hoE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; Received: from [142.133.48.188] (192.75.88.130) by BYAPR15MB2390.namprd15.prod.outlook.com (2603:10b6:a02:8c::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.17; Mon, 27 Aug 2018 19:12:06 +0000 Subject: Re: [PATCH 1/9] Do not pass NULL to memcpy To: Tom Tromey , References: <20180827145620.11055-1-tom@tromey.com> <20180827145620.11055-2-tom@tromey.com> From: Simon Marchi Message-ID: <5b410119-aae4-6911-f493-6d2c79e5c49e@ericsson.com> Date: Mon, 27 Aug 2018 19:12:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180827145620.11055-2-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-Path: simon.marchi@ericsson.com Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg00666.txt.bz2 On 2018-08-27 10:56 AM, Tom Tromey wrote: > -fsanitize=undefined pointed out a couple of spots that pass NULL to > memcpy, which is undefined behavior according to the C standard. > > ChangeLog > 2018-08-27 Tom Tromey > > * namespace.c (add_using_directive): Don't pass NULL to memcpy. > * dwarf2-frame.h (struct dwarf2_frame_state_reg_info): Don't pass > NULL to memcpy. > --- > gdb/ChangeLog | 6 ++++++ > gdb/dwarf2-frame.h | 3 ++- > gdb/namespace.c | 5 +++-- > 3 files changed, 11 insertions(+), 3 deletions(-) > > diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h > index 52316e5e168..6844010c8df 100644 > --- a/gdb/dwarf2-frame.h > +++ b/gdb/dwarf2-frame.h > @@ -110,7 +110,8 @@ struct dwarf2_frame_state_reg_info > size_t size = src.num_regs * sizeof (struct dwarf2_frame_state_reg); > > reg = (struct dwarf2_frame_state_reg *) xmalloc (size); > - memcpy (reg, src.reg, size); > + if (size > 0) > + memcpy (reg, src.reg, size); > } While the patch does not look wrong, I think the problem would "solve itself" "reg" was an std::vector, since an std::vector already has an appropriate copy constructor. It would also simplify a lot this area of the code, for example, the alloc_regs method would become a one-liner. > > /* Assignment operator for both move-assignment and copy-assignment. */ > diff --git a/gdb/namespace.c b/gdb/namespace.c > index be998d9d491..85c0c4b14d7 100644 > --- a/gdb/namespace.c > +++ b/gdb/namespace.c > @@ -111,8 +111,9 @@ add_using_directive (struct using_direct **using_directives, > else > newobj->declaration = declaration; > > - memcpy (newobj->excludes, excludes.data (), > - excludes.size () * sizeof (*newobj->excludes)); > + if (!excludes.empty ()) > + memcpy (newobj->excludes, excludes.data (), > + excludes.size () * sizeof (*newobj->excludes)); > newobj->excludes[excludes.size ()] = NULL; > > newobj->next = *using_directives; > Here too it would be nice to have make using_direct::excludes an std::vector, but it is not as simple, so I think adding that "if" is reasonnable. Simon