public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] rtla: Fix parse_cpu_set() bug introduced by strtoi()
@ 2026-01-12 19:26 Costa Shulyupin
  2026-01-13  0:43 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Costa Shulyupin @ 2026-01-12 19:26 UTC (permalink / raw)
  To: Steven Rostedt, Tomas Glozar, Costa Shulyupin,
	Wander Lairson Costa, Ivan Pravdin, Tiezhu Yang,
	linux-trace-kernel, linux-kernel

The patch 'Replace atoi() with a robust strtoi()' introduced a bug
in parse_cpu_set(), which relies on partial parsing of the input string.

The function parses CPU specifications like '0-3,5' by incrementing
a pointer through the string. strtoi() rejects strings with trailing
characters, causing parse_cpu_set() to fail on any CPU list with
multiple entries.

Restore the original use of atoi() in parse_cpu_set().

Fixes: 7e9dfccf8f11 ("rtla: Replace atoi() with a robust strtoi()")
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---

v2:
- Split the patch.

---
 tools/tracing/rtla/src/utils.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index 18986a5aed3c..0da3b2470c31 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -128,18 +128,16 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
 	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
 
 	for (p = cpu_list; *p; ) {
-		if (strtoi(p, &cpu))
-			goto err;
-		if (cpu < 0 || cpu >= nr_cpus)
+		cpu = atoi(p);
+		if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
 			goto err;
 
 		while (isdigit(*p))
 			p++;
 		if (*p == '-') {
 			p++;
-			if (strtoi(p, &end_cpu))
-				goto err;
-			if (end_cpu < cpu || end_cpu >= nr_cpus)
+			end_cpu = atoi(p);
+			if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
 				goto err;
 			while (isdigit(*p))
 				p++;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] rtla: Fix parse_cpu_set() bug introduced by strtoi()
  2026-01-12 19:26 [PATCH v2] rtla: Fix parse_cpu_set() bug introduced by strtoi() Costa Shulyupin
@ 2026-01-13  0:43 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2026-01-13  0:43 UTC (permalink / raw)
  To: Costa Shulyupin
  Cc: Steven Rostedt, Tomas Glozar, Wander Lairson Costa, Ivan Pravdin,
	Tiezhu Yang, linux-trace-kernel, linux-kernel

On Mon, 12 Jan 2026 21:26:41 +0200
Costa Shulyupin <costa.shul@redhat.com> wrote:

> The patch 'Replace atoi() with a robust strtoi()' introduced a bug
> in parse_cpu_set(), which relies on partial parsing of the input string.
> 
> The function parses CPU specifications like '0-3,5' by incrementing
> a pointer through the string. strtoi() rejects strings with trailing
> characters, causing parse_cpu_set() to fail on any CPU list with
> multiple entries.
> 
> Restore the original use of atoi() in parse_cpu_set().
> 
> Fixes: 7e9dfccf8f11 ("rtla: Replace atoi() with a robust strtoi()")
> Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>

Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> ---
> 
> v2:
> - Split the patch.
> 
> ---
>  tools/tracing/rtla/src/utils.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
> index 18986a5aed3c..0da3b2470c31 100644
> --- a/tools/tracing/rtla/src/utils.c
> +++ b/tools/tracing/rtla/src/utils.c
> @@ -128,18 +128,16 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
>  	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
>  
>  	for (p = cpu_list; *p; ) {
> -		if (strtoi(p, &cpu))
> -			goto err;
> -		if (cpu < 0 || cpu >= nr_cpus)
> +		cpu = atoi(p);
> +		if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
>  			goto err;
>  
>  		while (isdigit(*p))
>  			p++;
>  		if (*p == '-') {
>  			p++;
> -			if (strtoi(p, &end_cpu))
> -				goto err;
> -			if (end_cpu < cpu || end_cpu >= nr_cpus)
> +			end_cpu = atoi(p);
> +			if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
>  				goto err;
>  			while (isdigit(*p))
>  				p++;
> -- 
> 2.52.0
> 
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-13  0:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-12 19:26 [PATCH v2] rtla: Fix parse_cpu_set() bug introduced by strtoi() Costa Shulyupin
2026-01-13  0:43 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox