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

ruby-changes:47286

From: nagachika <ko1@a...>
Date: Sun, 23 Jul 2017 16:45:04 +0900 (JST)
Subject: [ruby-changes:47286] nagachika:r59401 (ruby_2_4): merge revision(s) 59161: [Backport #13672]

nagachika	2017-07-23 16:44:56 +0900 (Sun, 23 Jul 2017)

  New Revision: 59401

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

  Log:
    merge revision(s) 59161: [Backport #13672]
    
    parse.y: check multibyte char
    
    * parse.y (parser_precise_mbclen): check invalid multibyte char at
      skipping strings following `?x` literal string, not to stuck in
      a infinite loop.  [ruby-core:81746] [Bug #13672]

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/parse.y
    branches/ruby_2_4/test/ruby/test_parse.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 59400)
+++ ruby_2_4/version.h	(revision 59401)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.2"
 #define RUBY_RELEASE_DATE "2017-07-23"
-#define RUBY_PATCHLEVEL 152
+#define RUBY_PATCHLEVEL 153
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 7
Index: ruby_2_4/parse.y
===================================================================
--- ruby_2_4/parse.y	(revision 59400)
+++ ruby_2_4/parse.y	(revision 59401)
@@ -5176,7 +5176,6 @@ ripper_dispatch_delayed_token(struct par https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L5176
 
 #define parser_encoding_name()  (current_enc->name)
 #define parser_mbclen()  mbclen((lex_p-1),lex_pend,current_enc)
-#define parser_precise_mbclen()  rb_enc_precise_mbclen((lex_p-1),lex_pend,current_enc)
 #define is_identchar(p,e,enc) (rb_enc_isalnum((unsigned char)(*(p)),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,current_enc))
 
@@ -5248,6 +5247,17 @@ token_info_pop_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L5247
 }
 
 static int
+parser_precise_mbclen(struct parser_params *parser, const char *p)
+{
+    int len = rb_enc_precise_mbclen(p, lex_pend, current_enc);
+    if (!MBCLEN_CHARFOUND_P(len)) {
+	compile_error(PARSER_ARG "invalid multibyte char (%s)", parser_encoding_name());
+	return -1;
+    }
+    return len;
+}
+
+static int
 parser_yyerror(struct parser_params *parser, const char *msg)
 {
 #ifndef RIPPER
@@ -6058,11 +6068,8 @@ dispose_string(VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L6068
 static int
 parser_tokadd_mbchar(struct parser_params *parser, int c)
 {
-    int len = parser_precise_mbclen();
-    if (!MBCLEN_CHARFOUND_P(len)) {
-	compile_error(PARSER_ARG "invalid multibyte char (%s)", parser_encoding_name());
-	return -1;
-    }
+    int len = parser_precise_mbclen(parser, lex_p-1);
+    if (len < 0) return -1;
     tokadd(c);
     lex_p += --len;
     if (len > 0) tokcopy(len);
@@ -7550,7 +7557,8 @@ parse_qmark(struct parser_params *parser https://github.com/ruby/ruby/blob/trunk/ruby_2_4/parse.y#L7557
 	if (space_seen) {
 	    const char *start = lex_p - 1, *p = start;
 	    do {
-		int n = rb_enc_precise_mbclen(p, lex_pend, current_enc);
+		int n = parser_precise_mbclen(parser, p);
+		if (n < 0) return -1;
 		p += n;
 	    } while (p < lex_pend && is_identchar(p, lex_pend, current_enc));
 	    rb_warn2("`?' just followed by `%.*s' is interpreted as" \
Index: ruby_2_4/test/ruby/test_parse.rb
===================================================================
--- ruby_2_4/test/ruby/test_parse.rb	(revision 59400)
+++ ruby_2_4/test/ruby/test_parse.rb	(revision 59401)
@@ -512,6 +512,8 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_parse.rb#L512
     assert_raise(SyntaxError) { eval("?\v") }
     assert_raise(SyntaxError) { eval("?\r") }
     assert_raise(SyntaxError) { eval("?\f") }
+    assert_raise(SyntaxError) { eval("?\f") }
+    assert_raise(SyntaxError) { eval(" ?a\x8a".force_encoding("utf-8")) }
     assert_equal("\u{1234}", eval("?\u{1234}"))
     assert_equal("\u{1234}", eval('?\u{1234}'))
   end
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 59400)
+++ ruby_2_4	(revision 59401)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r59161

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

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