Return-Path: Received: from mail-bl2nam02on0095.outbound.protection.outlook.com ([104.47.38.95]:17369 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932757AbeCCW0w (ORCPT ); Sat, 3 Mar 2018 17:26:52 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Thomas Richter , Heiko Carstens , Martin Schwidefsky , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 063/102] perf annotate: Fix objdump comment parsing for Intel mov dissassembly Date: Sat, 3 Mar 2018 22:24:45 +0000 Message-ID: <20180303222318.26006-63-alexander.levin@microsoft.com> References: <20180303222318.26006-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222318.26006-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Thomas Richter [ Upstream commit 35a8a148d8c1ee9e5ae18f9565a880490f816f89 ] The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86): 23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15 # 234008 and the function mov__parse() is called to investigate the complete line. Mov__parse() breaks this line into several parts and finally calls function comment__symbol() to parse the data after the comment character '#'. Comment__symbol() expects a hexadecimal address followed by a symbol in '<' and '>' brackets. However the 2nd parameter given to function comment__symbol() always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit and strtoull() fails without being noticed. Fix this by advancing the second parameter to function comment__symbol() by one byte before invocation and add an error check after strtoull() has been called. Signed-off-by: Thomas Richter Reviewed-by: Hendrik Brueckner Acked-by: Ravi Bangoria Cc: Heiko Carstens Cc: Martin Schwidefsky Fixes: 6de783b6f50f ("perf annotate: Resolve symbols using objdump comment"= ) Link: http://lkml.kernel.org/r/20171128075632.72182-1-tmricht@linux.vnet.ib= m.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/annotate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 3369c7830260..6a631acf8bb7 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -322,6 +322,8 @@ static int comment__symbol(char *raw, char *comment, u6= 4 *addrp, char **namep) return 0; =20 *addrp =3D strtoull(comment, &endptr, 16); + if (endptr =3D=3D comment) + return 0; name =3D strchr(endptr, '<'); if (name =3D=3D NULL) return -1; @@ -435,8 +437,8 @@ static int mov__parse(struct arch *arch, struct ins_ope= rands *ops, struct map *m return 0; =20 comment =3D ltrim(comment); - comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source= .name); - comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target= .name); + comment__symbol(ops->source.raw, comment + 1, &ops->source.addr, &ops->so= urce.name); + comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->ta= rget.name); =20 return 0; =20 @@ -480,7 +482,7 @@ static int dec__parse(struct arch *arch __maybe_unused,= struct ins_operands *ops return 0; =20 comment =3D ltrim(comment); - comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target= .name); + comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->ta= rget.name); =20 return 0; } --=20 2.14.1