lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-2mdn8s2raatyhz7tamrsz22r@git.kernel.org>
Date:   Thu, 16 Feb 2017 12:00:02 -0800
From:   tip-bot for Arnaldo Carvalho de Melo <tipbot@...or.com>
To:     linux-tip-commits@...r.kernel.org
Cc:     dbueso@...e.de, wangnan0@...wei.com, linux-kernel@...r.kernel.org,
        jolsa@...nel.org, mingo@...nel.org, hpa@...or.com,
        jpoimboe@...hat.com, adrian.hunter@...el.com, namhyung@...nel.org,
        dsahern@...il.com, acme@...hat.com, tglx@...utronix.de
Subject: [tip:perf/core] tools lib subcmd: Make it an error to pass a signed
 value to OPTION_UINTEGER

Commit-ID:  b98897166280c4cfb9bc5a6c1b5682528eb4abff
Gitweb:     http://git.kernel.org/tip/b98897166280c4cfb9bc5a6c1b5682528eb4abff
Author:     Arnaldo Carvalho de Melo <acme@...hat.com>
AuthorDate: Tue, 14 Feb 2017 13:55:40 -0300
Committer:  Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Tue, 14 Feb 2017 15:19:17 -0300

tools lib subcmd: Make it an error to pass a signed value to OPTION_UINTEGER

Options marked OPTION_UINTEGER or OPTION_U64 clearly indicates that an
unsigned value is expected, so just error out when a negative value is
passed, instead of returning something undesired to the tool.

E.g.:

  # perf bench futex hash -t -4
  # Running 'futex/hash' benchmark:
   Error: switch `t' expects an unsigned numerical value
   Usage: perf bench futex hash <options>

      -t, --threads <n>     Specify amount of threads
  #

Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Davidlohr Bueso <dbueso@...e.de>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Wang Nan <wangnan0@...wei.com>
Link: http://lkml.kernel.org/n/tip-2mdn8s2raatyhz7tamrsz22r@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
 tools/lib/subcmd/parse-options.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c
index 8aad811..6bc2402 100644
--- a/tools/lib/subcmd/parse-options.c
+++ b/tools/lib/subcmd/parse-options.c
@@ -270,6 +270,8 @@ static int get_value(struct parse_opt_ctx_t *p,
 		}
 		if (get_arg(p, opt, flags, &arg))
 			return -1;
+		if (arg[0] == '-')
+			return opterror(opt, "expects an unsigned numerical value", flags);
 		*(unsigned int *)opt->value = strtol(arg, (char **)&s, 10);
 		if (*s)
 			return opterror(opt, "expects a numerical value", flags);
@@ -302,6 +304,8 @@ static int get_value(struct parse_opt_ctx_t *p,
 		}
 		if (get_arg(p, opt, flags, &arg))
 			return -1;
+		if (arg[0] == '-')
+			return opterror(opt, "expects an unsigned numerical value", flags);
 		*(u64 *)opt->value = strtoull(arg, (char **)&s, 10);
 		if (*s)
 			return opterror(opt, "expects a numerical value", flags);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ