summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-08-09 00:14:50 -0700
committerNamhyung Kim <namhyung@kernel.org>2026-08-09 22:02:38 -0700
commitb3d7c6c1a998c0dd4607558893ba03a374ee343f (patch)
tree3ddfd953a1ab3cd0a071b4adaa880b6f2e6f38ee /tools
parentb365402cd5ea9e932b1458ee966d2258105da75d (diff)
perf python: Add thread and PMU uninitialized checks
Add CHECK_INITIALIZED checks to the thread attribute getters (get_pid, get_tid, get_ppid) to prevent crashes if they are accessed before being properly initialized. Fixes: 3b96bf7af60d ("perf python: Add python session abstraction wrapping perf's session") Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/python.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index c70b151428f7..36c5f4b0d0bb 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1678,6 +1678,7 @@ static PyObject *pyrf_pmu__name(PyObject *self)
{
struct pyrf_pmu *ppmu = (void *)self;
+ CHECK_INITIALIZED(ppmu->pmu, "pmu");
return PyUnicode_FromString(ppmu->pmu->name);
}
@@ -1727,9 +1728,12 @@ static int pyrf_pmu__events_cb(void *state, struct pmu_event_info *info)
static PyObject *pyrf_pmu__events(PyObject *self)
{
struct pyrf_pmu *ppmu = (void *)self;
- PyObject *py_list = PyList_New(0);
+ PyObject *py_list;
int ret;
+ CHECK_INITIALIZED(ppmu->pmu, "pmu");
+
+ py_list = PyList_New(0);
if (!py_list)
return NULL;
@@ -1750,6 +1754,7 @@ static PyObject *pyrf_pmu__repr(PyObject *self)
{
struct pyrf_pmu *ppmu = (void *)self;
+ CHECK_INITIALIZED(ppmu->pmu, "pmu");
return PyUnicode_FromFormat("pmu(%s)", ppmu->pmu->name);
}
@@ -3764,21 +3769,25 @@ static PyMethodDef pyrf_thread__methods[] = {
static PyObject *pyrf_thread__get_pid(struct pyrf_thread *pthread, void *closure __maybe_unused)
{
+ CHECK_INITIALIZED(pthread->thread, "thread");
return PyLong_FromLong(thread__pid(pthread->thread));
}
static PyObject *pyrf_thread__get_tid(struct pyrf_thread *pthread, void *closure __maybe_unused)
{
+ CHECK_INITIALIZED(pthread->thread, "thread");
return PyLong_FromLong(thread__tid(pthread->thread));
}
static PyObject *pyrf_thread__get_ppid(struct pyrf_thread *pthread, void *closure __maybe_unused)
{
+ CHECK_INITIALIZED(pthread->thread, "thread");
return PyLong_FromLong(thread__ppid(pthread->thread));
}
static PyObject *pyrf_thread__get_cpu(struct pyrf_thread *pthread, void *closure __maybe_unused)
{
+ CHECK_INITIALIZED(pthread->thread, "thread");
return PyLong_FromLong(thread__cpu(pthread->thread));
}