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.
This commit is contained in:
W. J. van der Laan 2021-04-05 11:16:17 +00:00 committed by Jan (janneke) Nieuwenhuizen
parent c480c7e602
commit d7b2e0ab9b
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -320,8 +321,12 @@ SCM
make_frame (SCM stack, long index) make_frame (SCM stack, long index)
{ {
SCM frame_type = make_frame_type (); SCM frame_type = make_frame_type ();
SCM procedure = 0;
if (index != 0)
{
long array_index = (STACK_SIZE - (index * FRAME_SIZE)); long array_index = (STACK_SIZE - (index * FRAME_SIZE));
SCM procedure = g_stack_array[array_index + FRAME_PROCEDURE]; procedure = g_stack_array[array_index + FRAME_PROCEDURE];
}
if (!procedure) if (!procedure)
procedure = cell_f; procedure = cell_f;
SCM values = cell_nil; SCM values = cell_nil;