From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754430AbeAQQij (ORCPT ); Wed, 17 Jan 2018 11:38:39 -0500 Received: from terminus.zytor.com ([65.50.211.136]:46869 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753695AbeAQQih (ORCPT ); Wed, 17 Jan 2018 11:38:37 -0500 Date: Wed, 17 Jan 2018 08:35:49 -0800 From: tip-bot for Jin Yao Message-ID: Cc: linux-kernel@vger.kernel.org, kan.liang@intel.com, acme@redhat.com, peterz@infradead.org, hpa@zytor.com, mingo@kernel.org, yao.jin@linux.intel.com, alexander.shishkin@linux.intel.com, tglx@linutronix.de, ak@linux.intel.com, jolsa@redhat.com Reply-To: tglx@linutronix.de, jolsa@redhat.com, ak@linux.intel.com, alexander.shishkin@linux.intel.com, yao.jin@linux.intel.com, peterz@infradead.org, hpa@zytor.com, mingo@kernel.org, acme@redhat.com, kan.liang@intel.com, linux-kernel@vger.kernel.org In-Reply-To: <1515596433-24653-4-git-send-email-yao.jin@linux.intel.com> References: <1515596433-24653-4-git-send-email-yao.jin@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf util: Improve error checking for time percent input Git-Commit-ID: 6e761cbc9127fb8fc609aea2265ee8279b8d6c55 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 6e761cbc9127fb8fc609aea2265ee8279b8d6c55 Gitweb: https://git.kernel.org/tip/6e761cbc9127fb8fc609aea2265ee8279b8d6c55 Author: Jin Yao AuthorDate: Wed, 10 Jan 2018 23:00:28 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 17 Jan 2018 10:23:35 -0300 perf util: Improve error checking for time percent input The command line like 'perf report --stdio --time 1abc%/1' could be accepted by perf. It looks not very good. This patch uses strtod() to replace original atof() and check the entire string. Now for the same command line, it would return error message "Invalid time string". root@skl:/tmp# perf report --stdio --time 1abc%/1 Invalid time string Signed-off-by: Jin Yao Reviewed-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Kan Liang Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1515596433-24653-4-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/time-utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index 3f7f18f..88510ab 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c @@ -116,7 +116,8 @@ int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr) static int parse_percent(double *pcnt, char *str) { - char *c; + char *c, *endptr; + double d; c = strchr(str, '%'); if (c) @@ -124,8 +125,11 @@ static int parse_percent(double *pcnt, char *str) else return -1; - *pcnt = atof(str) / 100.0; + d = strtod(str, &endptr); + if (endptr != str + strlen(str)) + return -1; + *pcnt = d / 100.0; return 0; }