]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
libperf cpumap: Be tolerant of newline at the end of a cpumask
authorIan Rogers <irogers@google.com>
Fri, 6 Dec 2024 04:40:31 +0000 (20:40 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Dec 2024 20:52:41 +0000 (17:52 -0300)
File cpumasks often have a newline that shouldn't trigger the invalid
parsing case in perf_cpu_map__new().

Reviewed-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kyle Meyer <kyle.meyer@hpe.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20241206044035.1062032-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/cpumap.c

index eb02acd96225923d7a1f59b7733394005aedd185..f7bde19558e2b25b193813f1a20b1612cf574c15 100644 (file)
@@ -241,7 +241,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
                p = NULL;
                start_cpu = strtoul(cpu_list, &p, 0);
                if (start_cpu >= INT_MAX
-                   || (*p != '\0' && *p != ',' && *p != '-'))
+                   || (*p != '\0' && *p != ',' && *p != '-' && *p != '\n'))
                        goto invalid;
 
                if (*p == '-') {
@@ -249,7 +249,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
                        p = NULL;
                        end_cpu = strtoul(cpu_list, &p, 0);
 
-                       if (end_cpu >= INT_MAX || (*p != '\0' && *p != ','))
+                       if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',' && *p != '\n'))
                                goto invalid;
 
                        if (end_cpu < start_cpu)