]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-91048: Correct error path in testexternalinspection (#129557)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Thu, 13 Feb 2025 01:07:01 +0000 (01:07 +0000)
committerGitHub <noreply@github.com>
Thu, 13 Feb 2025 01:07:01 +0000 (01:07 +0000)
Modules/_testexternalinspection.c

index f1e331fea475c42eb85448a16e3f900f9315283c..77984460400c5d5f1f34453d780f65aacd48a341 100644 (file)
@@ -410,6 +410,7 @@ get_py_runtime(pid_t pid)
 {
     uintptr_t address = search_map_for_section(pid, "PyRuntime", "libpython");
     if (address == 0) {
+        PyErr_Clear();
         address = search_map_for_section(pid, "PyRuntime", "python");
     }
     return address;
@@ -1458,6 +1459,13 @@ get_stack_trace(PyObject* self, PyObject* args)
     }
 
     uintptr_t runtime_start_address = get_py_runtime(pid);
+    if (runtime_start_address == 0) {
+        if (!PyErr_Occurred()) {
+            PyErr_SetString(
+                PyExc_RuntimeError, "Failed to get .PyRuntime address");
+        }
+        return NULL;
+    }
     struct _Py_DebugOffsets local_debug_offsets;
 
     if (read_offsets(pid, &runtime_start_address, &local_debug_offsets)) {
@@ -1511,6 +1519,13 @@ get_async_stack_trace(PyObject* self, PyObject* args)
     }
 
     uintptr_t runtime_start_address = get_py_runtime(pid);
+    if (runtime_start_address == 0) {
+        if (!PyErr_Occurred()) {
+            PyErr_SetString(
+                PyExc_RuntimeError, "Failed to get .PyRuntime address");
+        }
+        return NULL;
+    }
     struct _Py_DebugOffsets local_debug_offsets;
 
     if (read_offsets(pid, &runtime_start_address, &local_debug_offsets)) {