Skip to content

Commit 7e01e05

Browse files
ambvpablogsal
andauthored
Add MAX_ITERATIONS
Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent 713ac39 commit 7e01e05

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Modules/_testexternalinspection.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,13 @@ append_awaited_by_for_thread(
14901490
return -1;
14911491
}
14921492

1493-
while ((uintptr_t)task_node.next != head_addr) {
1493+
size_t iteration_count = 0;
1494+
const size_t MAX_ITERATIONS = 100000; // Reasonable upper bound
1495+
while ((uintptr_t)task_node.next != head_addr) {
1496+
if (++iteration_count > MAX_ITERATIONS) {
1497+
PyErr_SetString(PyExc_RuntimeError, "Task list appears corrupted");
1498+
return -1;
1499+
}
14941500
uintptr_t task_addr = (uintptr_t)task_node.next
14951501
- async_offsets->asyncio_task_object.task_node;
14961502

0 commit comments

Comments
 (0)