Skip to content

Commit 39b6abe

Browse files
committed
Make sure to call PyErr before calling set_exception_cause
1 parent 9e622ab commit 39b6abe

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

Modules/_remote_debugging/asyncio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ iterate_set_entries(
117117

118118
// Validate mask and num_els to prevent huge loop iterations from garbage data
119119
if (mask < 0 || mask >= MAX_SET_TABLE_SIZE || num_els < 0 || num_els > mask + 1) {
120+
PyErr_SetString(PyExc_RuntimeError, "Invalid set object (corrupted remote memory)");
120121
set_exception_cause(unwinder, PyExc_RuntimeError,
121122
"Invalid set object (corrupted remote memory)");
122123
return -1;

Modules/_remote_debugging/code_objects.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ parse_code_object(RemoteUnwinderObject *unwinder,
446446
if (tlbc_entry) {
447447
// Validate index bounds (also catches negative values since tlbc_index is signed)
448448
if (ctx->tlbc_index < 0 || ctx->tlbc_index >= tlbc_entry->tlbc_array_size) {
449+
PyErr_Format(PyExc_RuntimeError,
450+
"Invalid tlbc_index %d (array size %zd, corrupted remote memory)",
451+
ctx->tlbc_index, tlbc_entry->tlbc_array_size);
449452
set_exception_cause(unwinder, PyExc_RuntimeError,
450453
"Invalid tlbc_index (corrupted remote memory)");
451454
goto error;

Modules/_remote_debugging/frames.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ process_single_stack_chunk(
4949
// Size must be at least enough for the header and reasonably bounded
5050
if (actual_size <= offsetof(_PyStackChunk, data) || actual_size > MAX_STACK_CHUNK_SIZE) {
5151
PyMem_RawFree(this_chunk);
52+
PyErr_Format(PyExc_RuntimeError,
53+
"Invalid stack chunk size %zu (corrupted remote memory)", actual_size);
5254
set_exception_cause(unwinder, PyExc_RuntimeError,
5355
"Invalid stack chunk size (corrupted remote memory)");
5456
return -1;
@@ -244,6 +246,7 @@ parse_frame_from_chunks(
244246
) {
245247
void *frame_ptr = find_frame_in_chunks(chunks, address);
246248
if (!frame_ptr) {
249+
PyErr_Format(PyExc_RuntimeError, "Frame at address 0x%lx not found in stack chunks", address);
247250
set_exception_cause(unwinder, PyExc_RuntimeError, "Frame not found in stack chunks");
248251
return -1;
249252
}

Modules/_remote_debugging/module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ _remote_debugging_RemoteUnwinder_get_stack_trace_impl(RemoteUnwinderObject *self
595595
// Detect cycle: if current_tstate didn't advance, we have corrupted data
596596
if (current_tstate == prev_tstate) {
597597
Py_DECREF(interpreter_threads);
598+
PyErr_Format(PyExc_RuntimeError,
599+
"Thread list cycle detected at address 0x%lx (corrupted remote memory)",
600+
current_tstate);
598601
set_exception_cause(self, PyExc_RuntimeError,
599602
"Thread list cycle detected (corrupted remote memory)");
600603
Py_CLEAR(result);

0 commit comments

Comments
 (0)