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

ruby-changes:50637

From: nagachika <ko1@a...>
Date: Sat, 17 Mar 2018 23:23:15 +0900 (JST)
Subject: [ruby-changes:50637] nagachika:r62797 (ruby_2_4): merge revision(s) 57484, 58767, 58938, 59041: [Backport #13863]

nagachika	2018-03-17 23:23:09 +0900 (Sat, 17 Mar 2018)

  New Revision: 62797

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

  Log:
    merge revision(s) 57484,58767,58938,59041: [Backport #13863]
    
    ruby.c: forbid options
    
    * ruby.c (forbid_setid): constified.
    
    * ruby.c (process_options): forbid if setid earlier.
    
    ruby.c: encode script name
    
    * ruby.c (process_options): encode script name to locale encoding
      instead of associate, if UTF-8 path.
    
    ruby.c: file in load_file argument
    
    * ruby.c (load_file): move opened file to an argument, to reduce
      open/close calls in the near future.
    
    ruby.c: script name in UTF-8
    
    * ruby.c (process_options): keep script name in UTF-8 if UTF8_PATH
      to get rid of loss by conversion.

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/ruby.c
    branches/ruby_2_4/version.h
Index: ruby_2_4/ruby.c
===================================================================
--- ruby_2_4/ruby.c	(revision 62796)
+++ ruby_2_4/ruby.c	(revision 62797)
@@ -175,8 +175,10 @@ cmdline_options_init(ruby_cmdline_option https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L175
     return opt;
 }
 
-static NODE *load_file(VALUE, VALUE, int, ruby_cmdline_options_t *);
-static void forbid_setid(const char *, ruby_cmdline_options_t *);
+static NODE *load_file(VALUE parser, VALUE fname, VALUE f, int script,
+		       ruby_cmdline_options_t *opt);
+static VALUE open_load_file(VALUE fname_v, int *xflag);
+static void forbid_setid(const char *, const ruby_cmdline_options_t *);
 #define forbid_setid(s) forbid_setid((s), opt)
 
 static struct {
@@ -423,6 +425,8 @@ str_conv_enc(VALUE str, rb_encoding *fro https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L425
 				ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE,
 				Qnil);
 }
+#else
+# define str_conv_enc(str, from, to) (str)
 #endif
 
 void ruby_init_loadpath_safe(int safe_level);
@@ -1050,6 +1054,7 @@ proc_options(long argc, char **argv, rub https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1054
 
 	  case 'x':
 	    if (envopt) goto noenvopt;
+	    forbid_setid("-x");
 	    opt->xflag = TRUE;
 	    s++;
 	    if (*s && chdir(s) < 0) {
@@ -1439,6 +1444,7 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1444
 {
     NODE *tree = 0;
     VALUE parser;
+    VALUE script_name;
     const rb_iseq_t *iseq;
     rb_encoding *enc, *lenc;
 #if UTF8_PATH
@@ -1514,6 +1520,9 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1520
 	    argc--;
 	    argv++;
 	}
+	if (opt->script[0] == '-' && !opt->script[1]) {
+	    forbid_setid("program input from stdin");
+	}
     }
 
     opt->script_name = rb_str_new_cstr(opt->script);
@@ -1560,9 +1569,17 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1569
 	ienc = enc;
 #endif
     }
-    rb_enc_associate(opt->script_name, lenc);
+    script_name = opt->script_name;
+    rb_enc_associate(opt->script_name,
+		     IF_UTF8_PATH(uenc = rb_utf8_encoding(), lenc));
+#if UTF8_PATH
+    if (uenc != lenc) {
+	opt->script_name = str_conv_enc(opt->script_name, uenc, lenc);
+	opt->script = RSTRING_PTR(opt->script_name);
+    }
+#endif
     rb_obj_freeze(opt->script_name);
-    if (IF_UTF8_PATH((uenc = rb_utf8_encoding()) != lenc, 1)) {
+    if (IF_UTF8_PATH(uenc != lenc, 1)) {
 	long i;
 	VALUE load_path = GET_VM()->load_path;
 	const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK;
@@ -1598,12 +1615,6 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1615
 	rb_funcallv(rb_cISeq, rb_intern_const("compile_option="), 1, &option);
 #undef SET_COMPILE_OPTION
     }
-#if UTF8_PATH
-    if (uenc != lenc) {
-	opt->script_name = str_conv_enc(opt->script_name, uenc, lenc);
-	opt->script = RSTRING_PTR(opt->script_name);
-    }
-#endif
     ruby_set_argv(argc, argv);
     process_sflag(&opt->sflag);
 
@@ -1641,13 +1652,11 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1652
 	tree = rb_parser_compile_string(parser, opt->script, opt->e_script, 1);
     }
     else {
-	if (opt->script[0] == '-' && !opt->script[1]) {
-	    forbid_setid("program input from stdin");
-	}
-
+	VALUE f;
 	base_block = toplevel_context(toplevel_binding);
 	rb_parser_set_context(parser, base_block, TRUE);
-	tree = load_file(parser, opt->script_name, 1, opt);
+	f = open_load_file(script_name, &opt->xflag);
+	tree = load_file(parser, opt->script_name, f, 1, opt);
     }
     ruby_set_script_name(opt->script_name);
     if (dump & DUMP_BIT(yydebug)) {
@@ -1704,7 +1713,7 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1713
     {
 	VALUE path = Qnil;
 	if (!opt->e_script && strcmp(opt->script, "-")) {
-	    path = rb_realpath_internal(Qnil, opt->script_name, 1);
+	    path = rb_realpath_internal(Qnil, script_name, 1);
 	}
 	base_block = toplevel_context(toplevel_binding);
 	iseq = rb_iseq_new_main(tree, opt->script_name, path, vm_block_iseq(base_block));
@@ -1743,7 +1752,6 @@ struct load_file_arg { https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1752
     VALUE parser;
     VALUE fname;
     int script;
-    int xflag;
     ruby_cmdline_options_t *opt;
     VALUE f;
 };
@@ -1761,7 +1769,6 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1769
     NODE *tree = 0;
     rb_encoding *enc;
     ID set_encoding;
-    int xflag = argp->xflag;
 
     argp->script = 0;
     CONST_ID(set_encoding, "set_encoding");
@@ -1777,11 +1784,9 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1784
 	enc = rb_ascii8bit_encoding();
 	rb_funcall(f, set_encoding, 1, rb_enc_from_encoding(enc));
 
-	if (xflag || opt->xflag) {
+	if (opt->xflag) {
 	    line_start--;
 	  search_shebang:
-	    forbid_setid("-x");
-	    opt->xflag = FALSE;
 	    while (!NIL_P(line = rb_io_gets(f))) {
 		line_start++;
 		RSTRING_GETMEM(line, str, len);
@@ -1874,7 +1879,8 @@ load_file_internal(VALUE argp_v) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1879
 static VALUE
 open_load_file(VALUE fname_v, int *xflag)
 {
-    const char *fname = StringValueCStr(fname_v);
+    const char *fname = (fname_v = rb_str_encode_ospath(fname_v),
+			 StringValueCStr(fname_v));
     long flen = RSTRING_LEN(fname_v);
     VALUE f;
     int e;
@@ -1975,15 +1981,14 @@ restore_load_file(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L1981
 }
 
 static NODE *
-load_file(VALUE parser, VALUE fname, int script, ruby_cmdline_options_t *opt)
+load_file(VALUE parser, VALUE fname, VALUE f, int script, ruby_cmdline_options_t *opt)
 {
     struct load_file_arg arg;
     arg.parser = parser;
     arg.fname = fname;
     arg.script = script;
     arg.opt = opt;
-    arg.xflag = 0;
-    arg.f = open_load_file(rb_str_encode_ospath(fname), &arg.xflag);
+    arg.f = f;
     return (NODE *)rb_ensure(load_file_internal, (VALUE)&arg,
 			     restore_load_file, (VALUE)&arg);
 }
@@ -1998,17 +2003,15 @@ rb_load_file(const char *fname) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L2003
 void *
 rb_load_file_str(VALUE fname_v)
 {
-    ruby_cmdline_options_t opt;
-
-    return load_file(rb_parser_new(), fname_v, 0, cmdline_options_init(&opt));
+    return rb_parser_load_file(rb_parser_new(), fname_v);
 }
 
 void *
 rb_parser_load_file(VALUE parser, VALUE fname_v)
 {
     ruby_cmdline_options_t opt;
-
-    return load_file(parser, fname_v, 0, cmdline_options_init(&opt));
+    VALUE f = open_load_file(fname_v, &cmdline_options_init(&opt)->xflag);
+    return load_file(parser, fname_v, f, 0, &opt);
 }
 
 /*
@@ -2117,7 +2120,7 @@ init_ids(ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ruby.c#L2120
 
 #undef forbid_setid
 static void
-forbid_setid(const char *s, ruby_cmdline_options_t *opt)
+forbid_setid(const char *s, const ruby_cmdline_options_t *opt)
 {
     if (opt->setids & 1)
         rb_raise(rb_eSecurityError, "no %s allowed while running setuid", s);
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 62796)
+++ ruby_2_4/version.h	(revision 62797)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.4"
 #define RUBY_RELEASE_DATE "2018-03-17"
-#define RUBY_PATCHLEVEL 260
+#define RUBY_PATCHLEVEL 261
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 62796)
+++ ruby_2_4	(revision 62797)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r57484,58767,58938,59041

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

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