From c554b4da71adae3dc7dd45f510a34bb822c959d9 Mon Sep 17 00:00:00 2001
From: Ben Gamari <ben@smart-cactus.org>
Date: Tue, 26 Sep 2023 17:27:12 -0400
Subject: [PATCH] rts/CloneStack: Bounds check array write

---
 rts/CloneStack.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rts/CloneStack.c b/rts/CloneStack.c
index c4fbbd00b277..9d474bfa196a 100644
--- a/rts/CloneStack.c
+++ b/rts/CloneStack.c
@@ -196,6 +196,9 @@ void copyPtrsToArray(Capability *cap, StgMutArrPtrs* arr, StgStack* stack) {
       index++;
     }
 
+    // Ensure that we didn't overflow the result array
+    ASSERT(index-1 < arr->ptrs);
+
     // check whether the stack ends in an underflow frame
     StgUnderflowFrame *frame = (StgUnderflowFrame *) (last_stack->stack
       + last_stack->stack_size - sizeofW(StgUnderflowFrame));
-- 
GitLab