changeset 29324:1a20cb5be8da stable

avoid crash when evaling global variables into existence in script (bug #59937) * stack-frame.cc (script_stack_frame::mark_scope): Resize frame if data offset is out of bounds. * test/bug-59937/bug-59937.tst, test/bug-59937/eval_global_script.m, test/bug-59937/module.mk: New test files. * test/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Jan 2021 15:13:06 -0500
parents 6264fb660f72
children e84b97e37f75 5fa1b4008204
files libinterp/corefcn/stack-frame.cc test/bug-59937/bug-59937.tst test/bug-59937/eval_global_script.m test/bug-59937/module.mk test/module.mk
diffstat 5 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/stack-frame.cc	Mon Jan 25 13:09:45 2021 -0500
+++ b/libinterp/corefcn/stack-frame.cc	Mon Jan 25 15:13:06 2021 -0500
@@ -1993,6 +1993,9 @@
   {
     size_t data_offset = sym.data_offset ();
 
+    if (data_offset >= size ())
+      resize_and_update_script_offsets (sym);
+
     // Redirection to evaluation context for the script.
 
     size_t frame_offset = m_lexical_frame_offsets.at (data_offset);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-59937/bug-59937.tst	Mon Jan 25 15:13:06 2021 -0500
@@ -0,0 +1,5 @@
+%!test
+%! eval_global_script
+%! assert (isglobal (new_var_name));
+%! assert (__varval__ (new_var_name), []);
+%! eval (sprintf ("clear -global %s", new_var_name));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-59937/eval_global_script.m	Mon Jan 25 15:13:06 2021 -0500
@@ -0,0 +1,2 @@
+new_var_name = matlab.lang.makeUniqueStrings ('somevar', who ());
+eval (sprintf ("global %s", new_var_name))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-59937/module.mk	Mon Jan 25 15:13:06 2021 -0500
@@ -0,0 +1,5 @@
+bug_59937_TEST_FILES = \
+  %reldir%/bug-59937.tst \
+  %reldir%/eval_global_script.m
+
+TEST_FILES += $(bug_59937_TEST_FILES)
--- a/test/module.mk	Mon Jan 25 13:09:45 2021 -0500
+++ b/test/module.mk	Mon Jan 25 15:13:06 2021 -0500
@@ -89,6 +89,7 @@
 include %reldir%/bug-59617/module.mk
 include %reldir%/bug-59661/module.mk
 include %reldir%/bug-59704/module.mk
+include %reldir%/bug-59937/module.mk
 include %reldir%/class-concat/module.mk
 include %reldir%/classdef/module.mk
 include %reldir%/classdef-multiple-inheritance/module.mk