From patchwork Thu Aug 8 13:54:43 2019 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: 34007 Received: (qmail 115183 invoked by alias); 8 Aug 2019 13:54:57 -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 115164 invoked by uid 89); 8 Aug 2019 13:54:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Aug 2019 13:54:55 +0000 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x78Dlr8R111928 for ; Thu, 8 Aug 2019 09:54:53 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2u8msv0qk8-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Aug 2019 09:54:53 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Aug 2019 14:54:52 +0100 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 8 Aug 2019 14:54:51 +0100 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x78Dso4I49873172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Aug 2019 13:54:50 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82BEF78060; Thu, 8 Aug 2019 13:54:50 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5717278063; Thu, 8 Aug 2019 13:54:50 +0000 (GMT) Received: from pedro.localdomain (unknown [9.18.235.137]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 8 Aug 2019 13:54:50 +0000 (GMT) Received: by pedro.localdomain (Postfix, from userid 1000) id 807B73C056B; Thu, 8 Aug 2019 10:54:47 -0300 (-03) From: Pedro Franco de Carvalho To: gdb-patches@sourceware.org Cc: kevinb@redhat.com Subject: [PATCH] Fix access to uninitialized variable in fill_in_stop_func Date: Thu, 8 Aug 2019 10:54:43 -0300 MIME-Version: 1.0 x-cbid: 19080813-0016-0000-0000-000009D8DAF1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011570; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000287; SDB=6.01243863; UDB=6.00656201; IPR=6.01025341; MB=3.00028092; MTD=3.00000008; XFM=3.00000015; UTC=2019-08-08 13:54:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19080813-0017-0000-0000-0000445933A3 Message-Id: <20190808135443.10894-1-pedromfc@linux.ibm.com> This patch changes fill_in_stop_func to check the return value of find_pc_partial_function before accessing the block pointer that is only written by find_pc_partial_function if it returns a success status. gdb/ChangeLog: YYYY-MM-DD Pedro Franco de Carvalho * infrun.c (fill_in_stop_func): Use return value of find_pc_partial_function, remove comment. --- gdb/infrun.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index a9588f896a..15c778c7f3 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4117,13 +4117,12 @@ fill_in_stop_func (struct gdbarch *gdbarch, { const block *block; - /* Don't care about return value; stop_func_start and stop_func_name - will both be 0 if it doesn't work. */ - find_pc_partial_function (ecs->event_thread->suspend.stop_pc, - &ecs->stop_func_name, - &ecs->stop_func_start, - &ecs->stop_func_end, - &block); + bool status = (find_pc_partial_function + (ecs->event_thread->suspend.stop_pc, + &ecs->stop_func_name, + &ecs->stop_func_start, + &ecs->stop_func_end, + &block)); /* The call to find_pc_partial_function, above, will set stop_func_start and stop_func_end to the start and end @@ -4133,7 +4132,7 @@ fill_in_stop_func (struct gdbarch *gdbarch, the function's start offset and entrypoint. Note that stop_func_start is NOT advanced when in a range of a non-contiguous block that does not contain the entry pc. */ - if (block != nullptr + if (status && block != nullptr && ecs->stop_func_start <= BLOCK_ENTRY_PC (block) && BLOCK_ENTRY_PC (block) < ecs->stop_func_end) {