From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71069 invoked by alias); 14 Nov 2018 17:23:15 -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 71058 invoked by uid 89); 14 Nov 2018 17:23:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=Notice 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 ESMTP; Wed, 14 Nov 2018 17:23:13 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B225558E5C; Wed, 14 Nov 2018 17:23:12 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D21F75DA2A; Wed, 14 Nov 2018 17:23:11 +0000 (UTC) Subject: Re: [PATCH] Fix buffer overflow in ada-lang.c:move_bits To: Joel Brobecker References: <20181024162037.21024-1-tom@tromey.com> <20181101153517.GA2705@adacore.com> <082f66ea-223b-52f4-bc24-b274dbcf4f01@redhat.com> <609409e6-235a-4724-3ced-57c3ff42e299@redhat.com> <20181109171641.GD18647@adacore.com> <20181114171116.GA6074@adacore.com> Cc: Tom Tromey , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <7628ab26-ad93-726c-f1d4-d5c60492115c@redhat.com> Date: Wed, 14 Nov 2018 17:23: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: <20181114171116.GA6074@adacore.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-11/txt/msg00228.txt.bz2 On 11/14/2018 05:11 PM, Joel Brobecker wrote: > Hello, > >>>> I was going to suggest that this would benefit from unit tests in >>>> the style of dwarf2read.c:copy_bitwise's, but, actually, isn't this >>>> exactly the same as copy_bitwise? Can we get rid of ada-lang.c:move_bits? >>>> (And maybe move copy_bitwise elsewhere?) >>> I meant to say dwarf2loc.c instead of dwarf2read.c. >> It does look exactly the same, doesn't it? I'll see if we can just >> re-use dwarf2loc's copy_bitwise. Thanks for the suggestion! > How about the attached? I ran it through AdaCore's testsuite on > all the platforms we support as well as the official testsuite on > x86_64-linux. No regression. > > gdb/ChangeLog: > > * ada-lang.c (move_bits): Delete. Update all callers to use > copy_bitwise instead. > * dwarf2loc.c (copy_bitwise, bits_to_str::bits_to_str) > (selftests::check_copy_bitwise, selftests::copy_bitwise_tests): > Move from here to utils.c. > (_initialize_dwarf2loc): Remove call to register copy_bitwise > selftests. > * utils.h (copy_bitwise): Add declaration. > * utils.c (copy_bitwise, bits_to_str::bits_to_str) > (selftests::check_copy_bitwise, selftests::copy_bitwise_tests): > Moved here from dwarf2loc.c. > (_initialize_utils): Register copy_bitwise selftests. > > Thank you! > -- Joel > > Great, thanks! Nit, since the function is now public, I'd consider moving the unit tests to under gdb/unittests/ instead, like, to a new copy_bitwise-selftests.c file. (I'm mildly thinking that'd be a better filename than utils-selftest.c because the function may well move again in the future. Notice how gdb_realpath's unit tests were left behind in gdb/utils.c even though gdb_realpath moved to common/pathstuff.c.) If you do that, you can drop the '#if GDB_SELF_TEST' around the tests, since files in that directory are not compiled if unit tests are disabled. Regardless, LGTM. Thanks, Pedro Alves