Skip to content

Commit 6ea8a20

Browse files
makelinuxlenticularis39
authored andcommitted
rtla: Fix parse_cpu_set() bug introduced by strtoi()
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: 7e9dfcc ("rtla: Replace atoi() with a robust strtoi()") Signed-off-by: Costa Shulyupin <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tomas Glozar <[email protected]>
1 parent fb8b818 commit 6ea8a20

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

tools/tracing/rtla/src/utils.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,16 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
128128
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
129129

130130
for (p = cpu_list; *p; ) {
131-
if (strtoi(p, &cpu))
132-
goto err;
133-
if (cpu < 0 || cpu >= nr_cpus)
131+
cpu = atoi(p);
132+
if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
134133
goto err;
135134

136135
while (isdigit(*p))
137136
p++;
138137
if (*p == '-') {
139138
p++;
140-
if (strtoi(p, &end_cpu))
141-
goto err;
142-
if (end_cpu < cpu || end_cpu >= nr_cpus)
139+
end_cpu = atoi(p);
140+
if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
143141
goto err;
144142
while (isdigit(*p))
145143
p++;

0 commit comments

Comments
 (0)