diff options
| author | Ian Rogers <[email protected]> | 2025-07-10 23:51:26 +0000 |
|---|---|---|
| committer | Namhyung Kim <[email protected]> | 2025-07-11 19:36:40 +0000 |
| commit | b4aff7ed7a4c1360e8b29d545c7bc9e05af1a995 (patch) | |
| tree | 296835f01e4df579a73a147ef8d654be4a7e962b /tools/perf/util/python.c | |
| parent | perf python: Improve leader copying from evlist (diff) | |
| download | kernel-b4aff7ed7a4c1360e8b29d545c7bc9e05af1a995.tar.gz kernel-b4aff7ed7a4c1360e8b29d545c7bc9e05af1a995.zip | |
perf python: Set index error for invalid thread/cpu map items
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Namhyung Kim <[email protected]>
Diffstat (limited to 'tools/perf/util/python.c')
| -rw-r--r-- | tools/perf/util/python.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 1d9fa33d377a..2f28f71325a8 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -529,8 +529,10 @@ static PyObject *pyrf_cpu_map__item(PyObject *obj, Py_ssize_t i) { struct pyrf_cpu_map *pcpus = (void *)obj; - if (i >= perf_cpu_map__nr(pcpus->cpus)) + if (i >= perf_cpu_map__nr(pcpus->cpus)) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } return Py_BuildValue("i", perf_cpu_map__cpu(pcpus->cpus, i).cpu); } @@ -598,8 +600,10 @@ static PyObject *pyrf_thread_map__item(PyObject *obj, Py_ssize_t i) { struct pyrf_thread_map *pthreads = (void *)obj; - if (i >= perf_thread_map__nr(pthreads->threads)) + if (i >= perf_thread_map__nr(pthreads->threads)) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i)); } |
