From d7b2e0ab9b416c4478dcdfc977e7880e0fcddd6f Mon Sep 17 00:00:00 2001 From: "W. J. van der Laan" Date: Mon, 5 Apr 2021 11:16:17 +0000 Subject: [PATCH] mes: Prevent out-of-bounds access for stack frame 0. * 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.c b/src/lib.c index 424a1ccc..918fc527 100644 --- a/src/lib.c +++ b/src/lib.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -320,8 +321,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;