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

ruby-changes:40380

From: nobu <ko1@a...>
Date: Fri, 6 Nov 2015 09:01:44 +0900 (JST)
Subject: [ruby-changes:40380] nobu:r52461 (trunk): parse.y: fix segv after invalid keyword argument

nobu	2015-11-06 09:01:29 +0900 (Fri, 06 Nov 2015)

  New Revision: 52461

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

  Log:
    parse.y: fix segv after invalid keyword argument
    
    * parse.y (kwd_append): fix segv after invalid keyword argument,
      preceding keyword list is NULL when syntax error is there.
      [ruby-core:71356] [Bug #11663]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52460)
+++ ChangeLog	(revision 52461)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Nov  6 09:01:26 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (kwd_append): fix segv after invalid keyword argument,
+	  preceding keyword list is NULL when syntax error is there.
+	  [ruby-core:71356] [Bug #11663]
+
 Fri Nov  6 06:59:37 2015  Eric Wong  <e@8...>
 
 	* test/ruby/test_autoload: hoist out ruby_impl_require
Index: parse.y
===================================================================
--- parse.y	(revision 52460)
+++ parse.y	(revision 52461)
@@ -466,6 +466,8 @@ static NODE *new_attr_op_assign_gen(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L466
 static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs);
 #define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs))
 
+static NODE *kwd_append(NODE*, NODE*);
+
 static NODE *new_hash_gen(struct parser_params *parser, NODE *hash);
 #define new_hash(hash) new_hash_gen(parser, (hash))
 
@@ -4779,13 +4781,7 @@ f_block_kwarg	: f_block_kw https://github.com/ruby/ruby/blob/trunk/parse.y#L4781
 		| f_block_kwarg ',' f_block_kw
 		    {
 		    /*%%%*/
-			NODE *kws = $1;
-
-			while (kws->nd_next) {
-			    kws = kws->nd_next;
-			}
-			kws->nd_next = $3;
-			$$ = $1;
+			$$ = kwd_append($1, $3);
 		    /*%
 			$$ = rb_ary_push($1, $3);
 		    %*/
@@ -4804,13 +4800,7 @@ f_kwarg		: f_kw https://github.com/ruby/ruby/blob/trunk/parse.y#L4800
 		| f_kwarg ',' f_kw
 		    {
 		    /*%%%*/
-			NODE *kws = $1;
-
-			while (kws->nd_next) {
-			    kws = kws->nd_next;
-			}
-			kws->nd_next = $3;
-			$$ = $1;
+			$$ = kwd_append($1, $3);
 		    /*%
 			$$ = rb_ary_push($1, $3);
 		    %*/
@@ -6805,6 +6795,9 @@ formal_argument_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L6795
       case ID_CLASS:
 	yyerror("formal argument cannot be a class variable");
 	return 0;
+      default:
+	yyerror("formal argument must be local variable");
+	return 0;
 #else
       default:
 	lhs = dispatch1(param_error, lhs);
@@ -9018,6 +9011,19 @@ gettable_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L9011
     compile_error(PARSER_ARG "identifier %"PRIsVALUE" is not valid to get", rb_id2str(id));
     return 0;
 }
+
+static NODE *
+kwd_append(NODE *kwlist, NODE *kw)
+{
+    if (kwlist) {
+	NODE *kws = kwlist;
+	while (kws->nd_next) {
+	    kws = kws->nd_next;
+	}
+	kws->nd_next = kw;
+    }
+    return kwlist;
+}
 #else  /* !RIPPER */
 static int
 id_is_var_gen(struct parser_params *parser, ID id)
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 52460)
+++ test/ruby/test_syntax.rb	(revision 52461)
@@ -193,6 +193,16 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L193
     end
   end
 
+  def test_keyword_invalid_name
+    bug11663 = '[ruby-core:71356] [Bug #11663]'
+
+    o = Object.new
+    assert_syntax_error('def o.foo(arg1?:) end', /arg1\?/, bug11663)
+    assert_syntax_error('def o.foo(arg1?:, arg2:) end', /arg1\?/, bug11663)
+    assert_syntax_error('proc {|arg1?:|}', /arg1\?/, bug11663)
+    assert_syntax_error('proc {|arg1?:, arg2:|}', /arg1\?/, bug11663)
+  end
+
   def test_optional_self_reference
     bug9593 = '[ruby-core:61299] [Bug #9593]'
     o = Object.new

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

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