Skip to content

Commit 2ea5ec3

Browse files
committed
perf python: Set index error for invalid thread/cpu map items
JIRA: https://issues.redhat.com/browse/RHEL-78198 upstream ======== commit b4aff7e Author: Ian Rogers <irogers@google.com> Date: Thu Jul 10 16:51:26 2025 -0700 description =========== Returning NULL for out of bound CPU or thread map items causes internal errors. Fix by correctly setting the error to be an index error. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20250710235126.1086011-14-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent 5f3e37d commit 2ea5ec3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/perf/util/python.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,10 @@ static PyObject *pyrf_cpu_map__item(PyObject *obj, Py_ssize_t i)
529529
{
530530
struct pyrf_cpu_map *pcpus = (void *)obj;
531531

532-
if (i >= perf_cpu_map__nr(pcpus->cpus))
532+
if (i >= perf_cpu_map__nr(pcpus->cpus)) {
533+
PyErr_SetString(PyExc_IndexError, "Index out of range");
533534
return NULL;
535+
}
534536

535537
return Py_BuildValue("i", perf_cpu_map__cpu(pcpus->cpus, i).cpu);
536538
}
@@ -598,8 +600,10 @@ static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i)
598600
{
599601
struct pyrf_thread_map *pthreads = (void *)obj;
600602

601-
if (i >= perf_thread_map__nr(pthreads->threads))
603+
if (i >= perf_thread_map__nr(pthreads->threads)) {
604+
PyErr_SetString(PyExc_IndexError, "Index out of range");
602605
return NULL;
606+
}
603607

604608
return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i));
605609
}

0 commit comments

Comments
 (0)