Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753506AbbGALyp (ORCPT ); Wed, 1 Jul 2015 07:54:45 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:46261 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750935AbbGALyb (ORCPT ); Wed, 1 Jul 2015 07:54:31 -0400 From: He Kuang To: , , , , , CC: , , , Subject: [PATCH v2 2/2] perf probe: Add failure check when show variable range Date: Wed, 1 Jul 2015 11:53:24 +0000 Message-ID: <1435751604-145643-2-git-send-email-hekuang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1435751604-145643-1-git-send-email-hekuang@huawei.com> References: <5593C843.6000200@hitachi.com> <1435751604-145643-1-git-send-email-hekuang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.210] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1807 Lines: 68 Change improper type size_t to diffptr_t to make consistent with libdw and handle error code. Signed-off-by: He Kuang --- tools/perf/util/dwarf-aux.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 2cb4c82..7658fb4 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -965,7 +965,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, { Dwarf_Die *scopes; int count; - size_t offset = 0; + ptrdiff_t offset = 0; Dwarf_Addr base; Dwarf_Addr start, end; Dwarf_Addr entry; @@ -991,6 +991,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, while ((offset = dwarf_ranges(&scopes[1], offset, &base, &start, &end)) > 0) { + start -= entry; end -= entry; @@ -1004,6 +1005,11 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die, } } + if (offset < 0) { + ret = -EINVAL; + goto out; + } + if (!first) strbuf_addf(buf, "]>"); @@ -1029,7 +1035,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) Dwarf_Addr entry; Dwarf_Op *op; size_t nops; - size_t offset = 0; + ptrdiff_t offset = 0; Dwarf_Attribute attr; bool first = true; const char *name; @@ -1067,6 +1073,9 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf) } } + if (offset < 0) + return -EINVAL; + if (!first) strbuf_addf(buf, "]>"); -- 1.8.5.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/