bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] mes: Prevent out-of-bounds access for stack frame 0


From: W. J. van der Laan
Subject: [PATCH] mes: Prevent out-of-bounds access for stack frame 0
Date: Mon, 05 Apr 2021 11:16:17 +0000

* src/lib.c (make_frame): Add a check to prevent reads outside of the
stack when trying to determine the procedure for stack frame 0.
---
 src/lib.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Avoids a segmentation fault or a random value which mucks up things later while 
printing a traceback.

diff --git a/src/lib.c b/src/lib.c
index 
424a1cccc377f67e55651bfc47f99100225b5e1f..35bdd0c45d85b7e60d2441beaa993cf21608fe3f
 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -320,8 +320,12 @@ SCM
 make_frame (SCM stack, long index)
 {
   SCM frame_type = make_frame_type ();
-  long array_index = (STACK_SIZE - (index * FRAME_SIZE));
-  SCM procedure = g_stack_array[array_index + FRAME_PROCEDURE];
+  SCM procedure = 0;
+  if (index != 0)
+    {
+      long array_index = (STACK_SIZE - (index * FRAME_SIZE));
+      procedure = g_stack_array[array_index + FRAME_PROCEDURE];
+    }
   if (!procedure)
     procedure = cell_f;
   SCM values = cell_nil;
--
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]