From patchwork Mon Oct 22 22:32:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Franco de Carvalho X-Patchwork-Id: 29834 Received: (qmail 126416 invoked by alias); 22 Oct 2018 22:33:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 126245 invoked by uid 89); 22 Oct 2018 22:33:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:D*de.ibm.com X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 Oct 2018 22:33:41 +0000 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9MMTEks104065 for ; Mon, 22 Oct 2018 18:33:39 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2n9kyjra3n-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 22 Oct 2018 18:33:39 -0400 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Oct 2018 18:33:38 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 22 Oct 2018 18:33:35 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9MMXXk424707232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Oct 2018 22:33:33 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 20567AE063; Mon, 22 Oct 2018 22:33:33 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E3FCFAE05F; Mon, 22 Oct 2018 22:33:32 +0000 (GMT) Received: from pedro.localdomain (unknown [9.85.173.33]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 22 Oct 2018 22:33:32 +0000 (GMT) Received: by pedro.localdomain (Postfix, from userid 1000) id 53D8C3C03DA; Mon, 22 Oct 2018 19:33:30 -0300 (-03) From: Pedro Franco de Carvalho To: gdb-patches@sourceware.org Cc: uweigand@de.ibm.com, edjunior@gmail.com Subject: [PATCH v5 01/12] Zero-initialize linux note sections Date: Mon, 22 Oct 2018 19:32:31 -0300 In-Reply-To: <20181022223242.7858-1-pedromfc@linux.ibm.com> References: <20181022223242.7858-1-pedromfc@linux.ibm.com> x-cbid: 18102222-0068-0000-0000-00000351A5FF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009918; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000268; SDB=6.01106526; UDB=6.00573028; IPR=6.00886611; MB=3.00023862; MTD=3.00000008; XFM=3.00000015; UTC=2018-10-22 22:33:36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18102222-0069-0000-0000-00004629FC27 Message-Id: <20181022223242.7858-2-pedromfc@linux.ibm.com> This patches changes linux-tdep.c so that the buffer used to write note sections when generating a core file is zero-initialized. This way, bytes that are not collected won't contain random data (e.g. padding bytes). gdb/ChangeLog: YYYY-MM-DD Pedro Franco de Carvalho * linux-tdep.c (linux_collect_regset_section_cb): Use std::vector instead of char * and malloc for buf. Remove xfree. --- gdb/linux-tdep.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 352114943f..c958c0dfe9 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1584,7 +1584,6 @@ linux_collect_regset_section_cb (const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data) { - char *buf; struct linux_collect_regset_section_cb_data *data = (struct linux_collect_regset_section_cb_data *) cb_data; bool variable_size_section = (regset != NULL @@ -1598,19 +1597,22 @@ linux_collect_regset_section_cb (const char *sect_name, int supply_size, gdb_assert (regset && regset->collect_regset); - buf = (char *) xmalloc (collect_size); - regset->collect_regset (regset, data->regcache, -1, buf, collect_size); + /* This is intentionally zero-initialized by using std::vector, so + that any padding bytes in the core file will show as 0. */ + std::vector buf (collect_size); + + regset->collect_regset (regset, data->regcache, -1, buf.data (), + collect_size); /* PRSTATUS still needs to be treated specially. */ if (strcmp (sect_name, ".reg") == 0) data->note_data = (char *) elfcore_write_prstatus (data->obfd, data->note_data, data->note_size, data->lwp, - gdb_signal_to_host (data->stop_signal), buf); + gdb_signal_to_host (data->stop_signal), buf.data ()); else data->note_data = (char *) elfcore_write_register_note (data->obfd, data->note_data, data->note_size, - sect_name, buf, collect_size); - xfree (buf); + sect_name, buf.data (), collect_size); if (data->note_data == NULL) data->abort_iteration = 1;