octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #29491] recursive source() causes segfault


From: Judd Storrs
Subject: [Octave-bug-tracker] [bug #29491] recursive source() causes segfault
Date: Fri, 09 Apr 2010 18:41:32 +0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8

Follow-up Comment #1, bug #29491 (project octave):

One way to fix this would be to limit the depth of source file nesting. This
would prevent other runaway circular sourcing as well as the recursive
example. Something like this works for me with limited testing so far:

diff -r 724e19a1bd3f src/oct-parse.yy
--- a/src/oct-parse.yy  Thu Apr 08 18:43:47 2010 -0400
+++ b/src/oct-parse.yy  Fri Apr 09 14:30:41 2010 -0400
@@ -118,6 +118,15 @@
 // we have nested functions or just implicitly ended subfunctions.
 static int max_function_depth = 0;
 
+// Maximum nesting level for source_file()
+static int max_source_file_depth = 256;
+
+// = 0 currently outside any sourced file.
+// = 1 inside the first sourced file.
+// > 1 means we are looking at a sourced file included by another
+//   sourced file.
+static int current_source_file_depth = 0;
+
 // FALSE if we are still at the primary function. Subfunctions can
 // only be declared inside function files.
 static int parsing_subfunctions = false;
@@ -3881,8 +3890,13 @@
         frame.add_fcn (octave_call_stack::pop);
     }      
 
+  if ( current_source_file_depth == max_source_file_depth )
+    error ("source: too many nested source files");
+
   if (! error_state)
     {
+      current_source_file_depth++ ;
+
       octave_function *fcn = parse_fcn_file (file_full_name, "", true,
                                              require_file, warn_for);
 
@@ -3910,6 +3924,8 @@
       else
         error ("source: error sourcing file `%s'",
                file_full_name.c_str ());
+
+      current_source_file_depth-- ;
     }
 }



I'm not sure this follows octave's coding style and I need some pointers: 

0 Is frame_protect needed/desired on current_source_file_depth?
0 What's a suggested maximum depth? I used Vmax_recursion_limit which is
256.
0 Are sanity checks needed somewhere to verify that current_source_file_depth
is 0 at certain entry points?

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?29491>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

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