2022-09-26 03:21:39

by Chen Zhongjin

[permalink] [raw]
Subject: [PATCH -next 2/5] perf: Fix incorrectly parsed flags in filter

When parsing flags in filter, the strtoul function uses wrong parsing
condition (tok[1] = 'x'), which can make the flags be corrupted and
treat all numbers start with 0 as hex.

In fact strtoul() will auto test hex format when base == 0 (See
_parse_integer_fixup_radix). So there is no need to test this again.

Remove the unnessesary is_hexa test.

Fixes: 154c978d484c ("libbeauty: Introduce strarray__strtoul_flags()")
Signed-off-by: Chen Zhongjin <[email protected]>
---
tools/perf/builtin-trace.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c7bb7a8222a6..7ecd76428440 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -615,11 +615,8 @@ bool strarray__strtoul_flags(struct strarray *sa, char *bf, size_t size, u64 *re
if (isalpha(*tok) || *tok == '_') {
if (!strarray__strtoul(sa, tok, toklen, &val))
return false;
- } else {
- bool is_hexa = tok[0] == 0 && (tok[1] = 'x' || tok[1] == 'X');
-
- val = strtoul(tok, NULL, is_hexa ? 16 : 0);
- }
+ } else
+ val = strtoul(tok, NULL, 0);

*ret |= (1 << (val - 1));

--
2.17.1


2022-09-26 21:18:26

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH -next 2/5] perf: Fix incorrectly parsed flags in filter

Em Mon, Sep 26, 2022 at 11:14:37AM +0800, Chen Zhongjin escreveu:
> When parsing flags in filter, the strtoul function uses wrong parsing
> condition (tok[1] = 'x'), which can make the flags be corrupted and
> treat all numbers start with 0 as hex.
>
> In fact strtoul() will auto test hex format when base == 0 (See
> _parse_integer_fixup_radix). So there is no need to test this again.
>
> Remove the unnessesary is_hexa test.

Thanks, applied.

- Arnaldo


> Fixes: 154c978d484c ("libbeauty: Introduce strarray__strtoul_flags()")
> Signed-off-by: Chen Zhongjin <[email protected]>
> ---
> tools/perf/builtin-trace.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index c7bb7a8222a6..7ecd76428440 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -615,11 +615,8 @@ bool strarray__strtoul_flags(struct strarray *sa, char *bf, size_t size, u64 *re
> if (isalpha(*tok) || *tok == '_') {
> if (!strarray__strtoul(sa, tok, toklen, &val))
> return false;
> - } else {
> - bool is_hexa = tok[0] == 0 && (tok[1] = 'x' || tok[1] == 'X');
> -
> - val = strtoul(tok, NULL, is_hexa ? 16 : 0);
> - }
> + } else
> + val = strtoul(tok, NULL, 0);
>
> *ret |= (1 << (val - 1));
>
> --
> 2.17.1

--

- Arnaldo