[前][次][番号順一覧][スレッド一覧]

ruby-changes:45836

From: naruse <ko1@a...>
Date: Sun, 12 Mar 2017 23:03:22 +0900 (JST)
Subject: [ruby-changes:45836] naruse:r57909 (ruby_2_4): merge revision(s) 57660: [Backport #13234]

naruse	2017-03-12 23:03:16 +0900 (Sun, 12 Mar 2017)

  New Revision: 57909

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57909

  Log:
    merge revision(s) 57660: [Backport #13234]
    
    regparse.c: initialize return values
    
    * regparse.c (parse_char_class): initialize return values before
      depth limit check.  returned values will be freed in callers
      regardless the error.  [ruby-core:79624] [Bug #13234]

  Added directories:
    branches/ruby_2_4/ext/-test-/regexp/
  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/regparse.c
    branches/ruby_2_4/test/ruby/test_regexp.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 57908)
+++ ruby_2_4/version.h	(revision 57909)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.0"
 #define RUBY_RELEASE_DATE "2017-03-12"
-#define RUBY_PATCHLEVEL 65
+#define RUBY_PATCHLEVEL 66
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_4/regparse.c
===================================================================
--- ruby_2_4/regparse.c	(revision 57908)
+++ ruby_2_4/regparse.c	(revision 57909)
@@ -4570,11 +4570,11 @@ parse_char_class(Node** np, Node** asc_n https://github.com/ruby/ruby/blob/trunk/ruby_2_4/regparse.c#L4570
   enum CCVALTYPE val_type, in_type;
   int val_israw, in_israw;
 
+  *np = *asc_np = NULL_NODE;
   env->parse_depth++;
   if (env->parse_depth > ParseDepthLimit)
     return ONIGERR_PARSE_DEPTH_LIMIT_OVER;
   prev_cc = asc_prev_cc = (CClassNode* )NULL;
-  *np = *asc_np = NULL_NODE;
   r = fetch_token_in_cc(tok, src, end, env);
   if (r == TK_CHAR && tok->u.c == '^' && tok->escaped == 0) {
     neg = 1;
Index: ruby_2_4/ext/-test-/regexp/init.c
===================================================================
--- ruby_2_4/ext/-test-/regexp/init.c	(revision 0)
+++ ruby_2_4/ext/-test-/regexp/init.c	(revision 57909)
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ext/-test-/regexp/init.c#L1
+#include "ruby.h"
+
+#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);}
+
+void
+Init_regexp(void)
+{
+    VALUE mBug = rb_define_module("Bug");
+    VALUE klass = rb_define_class_under(mBug, "Regexp", rb_cRegexp);
+    TEST_INIT_FUNCS(init);
+}

Property changes on: ruby_2_4/ext/-test-/regexp/init.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_4/ext/-test-/regexp/extconf.rb
===================================================================
--- ruby_2_4/ext/-test-/regexp/extconf.rb	(revision 0)
+++ ruby_2_4/ext/-test-/regexp/extconf.rb	(revision 57909)
@@ -0,0 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ext/-test-/regexp/extconf.rb#L1
+# frozen_string_literal: false
+require_relative "../auto_ext.rb"
+auto_ext

Property changes on: ruby_2_4/ext/-test-/regexp/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_4/ext/-test-/regexp/parse_depth_limit.c
===================================================================
--- ruby_2_4/ext/-test-/regexp/parse_depth_limit.c	(revision 0)
+++ ruby_2_4/ext/-test-/regexp/parse_depth_limit.c	(revision 57909)
@@ -0,0 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ext/-test-/regexp/parse_depth_limit.c#L1
+#include <ruby.h>
+#include <ruby/onigmo.h>
+
+static VALUE
+get_parse_depth_limit(VALUE self)
+{
+    unsigned int depth = onig_get_parse_depth_limit();
+    return UINT2NUM(depth);
+}
+
+static VALUE
+set_parse_depth_limit(VALUE self, VALUE depth)
+{
+    onig_set_parse_depth_limit(NUM2UINT(depth));
+    return depth;
+}
+
+void
+Init_parse_depth_limit(VALUE klass)
+{
+    rb_define_singleton_method(klass, "parse_depth_limit", get_parse_depth_limit, 0);
+    rb_define_singleton_method(klass, "parse_depth_limit=", set_parse_depth_limit, 1);
+}

Property changes on: ruby_2_4/ext/-test-/regexp/parse_depth_limit.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_4/test/ruby/test_regexp.rb
===================================================================
--- ruby_2_4/test/ruby/test_regexp.rb	(revision 57908)
+++ ruby_2_4/test/ruby/test_regexp.rb	(revision 57909)
@@ -1198,6 +1198,25 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_regexp.rb#L1198
     RUBY
   end
 
+  def test_invalid_free_at_parse_depth_limit_over
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+      begin
+        require '-test-/regexp'
+      rescue LoadError
+      else
+        bug = '[ruby-core:79624] [Bug #13234]'
+        Bug::Regexp.parse_depth_limit = 10
+        src = "[" * 100
+        3.times do
+          assert_raise_with_message(RegexpError, /parse depth limit over/, bug) do
+            Regexp.new(src)
+          end
+        end
+      end
+    end;
+  end
+
   # This assertion is for porting x2() tests in testpy.py of Onigmo.
   def assert_match_at(re, str, positions, msg = nil)
     re = Regexp.new(re) unless re.is_a?(Regexp)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57660


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]