Skip to content

Commit 2576f8b

Browse files
committed
Protect against more errors with no exceptions
1 parent 0338ee1 commit 2576f8b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Modules/_remote_debugging_module.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
#endif
7676
#define INTERP_STATE_BUFFER_SIZE MAX(INTERP_STATE_MIN_SIZE, 256)
7777

78-
78+
#define MAX_TLBC_SIZE 2048
7979

8080
// Copied from Modules/_asynciomodule.c because it's not exported
8181

@@ -1594,10 +1594,16 @@ cache_tlbc_array(RemoteUnwinderObject *unwinder, uintptr_t code_addr, uintptr_t
15941594
return 0; // Invalid size
15951595
}
15961596

1597+
if (tlbc_size > MAX_TLBC_SIZE) {
1598+
PyErr_SetString(PyExc_RuntimeError, "TLBC array size exceeds maximum limit");
1599+
return 0; // Invalid size
1600+
}
1601+
15971602
// Allocate and read the entire TLBC array
15981603
size_t array_data_size = tlbc_size * sizeof(void*);
15991604
tlbc_array = PyMem_RawMalloc(sizeof(Py_ssize_t) + array_data_size);
16001605
if (!tlbc_array) {
1606+
PyErr_NoMemory();
16011607
set_exception_cause(unwinder, PyExc_MemoryError, "Failed to allocate TLBC array");
16021608
return 0; // Memory error
16031609
}
@@ -1611,6 +1617,7 @@ cache_tlbc_array(RemoteUnwinderObject *unwinder, uintptr_t code_addr, uintptr_t
16111617
// Create cache entry
16121618
entry = PyMem_RawMalloc(sizeof(TLBCCacheEntry));
16131619
if (!entry) {
1620+
PyErr_NoMemory();
16141621
PyMem_RawFree(tlbc_array);
16151622
set_exception_cause(unwinder, PyExc_MemoryError, "Failed to allocate TLBC cache entry");
16161623
return 0; // Memory error
@@ -1791,6 +1798,7 @@ parse_code_object(RemoteUnwinderObject *unwinder,
17911798

17921799
meta = PyMem_RawMalloc(sizeof(CachedCodeMetadata));
17931800
if (!meta) {
1801+
PyErr_NoMemory();
17941802
set_exception_cause(unwinder, PyExc_MemoryError, "Failed to allocate cached code metadata");
17951803
goto error;
17961804
}

0 commit comments

Comments
 (0)