Permalink
Browse files

limit the traced variable depth to reasonable 10

  • Loading branch information...
siuying committed Apr 18, 2012
1 parent f8fb2d7 commit df8136ddd859269f991250a5564584c28471cca7
Showing with 11 additions and 4 deletions.
  1. +5 −1 lib/instant/context.rb
  2. +6 −3 lib/instant/runner.rb
View
@@ -12,6 +12,11 @@ def initialize(keys=[])
def append(key, value)
@logs[key] ||= []
+
+ if @logs[key].length + 1 > 10
+ raise ::Instant::LoopTooDeepError.new("Loop too much")
+ end
+
@logs[key] << value
end
@@ -65,7 +70,6 @@ def loop_inside_end
@loop_counter = @loop_counter + 1
if @loop_counter > 1000
- self.loop_end
raise ::Instant::LoopTooDeepError.new("Loop too much")
end
end
View
@@ -10,9 +10,12 @@ def run(source)
begin
@processed = @processor.process(source)
context = Context.new
-
- return_value = context.instance_eval(@processed)
- context.close
+
+ begin
+ return_value = context.instance_eval(@processed)
+ ensure
+ context.close
+ end
{:status => :ok, :result => context.to_s, :return_value => return_value}
rescue SyntaxError => e
{:status => :error, :cause => :syntax_error, :message => format_error(e), :result => context.to_s }

0 comments on commit df8136d

Please sign in to comment.