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

ruby-changes:40886

From: ko1 <ko1@a...>
Date: Wed, 9 Dec 2015 00:15:06 +0900 (JST)
Subject: [ruby-changes:40886] ko1:r52965 (trunk): * compile.c (ibf_setup_load): rename to ibf_load_setup().

ko1	2015-12-09 00:14:55 +0900 (Wed, 09 Dec 2015)

  New Revision: 52965

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

  Log:
    * compile.c (ibf_setup_load): rename to ibf_load_setup().
    
    * compile.c (iseq_load_setup): check binary format.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52964)
+++ ChangeLog	(revision 52965)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec  9 00:13:09 2015  Koichi Sasada  <ko1@a...>
+
+	* compile.c (ibf_setup_load): rename to ibf_load_setup().
+
+	* compile.c (iseq_load_setup): check binary format.
+
 Tue Dec  8 23:30:07 2015  Naohisa Goto  <ngotogenome@g...>
 
 	* test/io/console/test_io_console.rb (run_pty): Avoid waiting twice
Index: compile.c
===================================================================
--- compile.c	(revision 52964)
+++ compile.c	(revision 52965)
@@ -8193,8 +8193,11 @@ ibf_load_iseq(const struct ibf_load *loa https://github.com/ruby/ruby/blob/trunk/compile.c#L8193
 }
 
 static void
-ibf_setup_load(struct ibf_load *load, VALUE loader_obj, VALUE str)
+ibf_load_setup(struct ibf_load *load, VALUE loader_obj, VALUE str)
 {
+    if (RSTRING_LENINT(str) < sizeof(struct ibf_header)) {
+	rb_raise(rb_eRuntimeError, "broken binary format");
+    }
     RB_OBJ_WRITE(loader_obj, &load->str, str);
     load->loader_obj = loader_obj;
     load->buff = StringValuePtr(str);
@@ -8203,6 +8206,21 @@ ibf_setup_load(struct ibf_load *load, VA https://github.com/ruby/ruby/blob/trunk/compile.c#L8206
     RB_OBJ_WRITE(loader_obj, &load->obj_list, rb_ary_tmp_new(0));
     load->id_list = ZALLOC_N(ID, load->header->id_list_size);
     load->iseq = NULL;
+
+    if (RSTRING_LENINT(str) < (int)load->header->size) {
+	rb_raise(rb_eRuntimeError, "broken binary format");
+    }
+    if (strncmp(load->header->magic, "YARB", 4) != 0) {
+	rb_raise(rb_eRuntimeError, "unkown binary format");
+    }
+    if (load->header->major_version != ISEQ_MAJOR_VERSION ||
+	load->header->minor_version != ISEQ_MINOR_VERSION) {
+	rb_raise(rb_eRuntimeError, "unmatched version file (%u.%u for %u.%u)",
+		 load->header->major_version, load->header->minor_version, ISEQ_MAJOR_VERSION, ISEQ_MINOR_VERSION);
+    }
+    if (strcmp(load->buff + sizeof(struct ibf_header), RUBY_PLATFORM) != 0) {
+	rb_raise(rb_eRuntimeError, "unmatched platform");
+    }
 }
 
 static void
@@ -8251,7 +8269,7 @@ iseq_ibf_load(VALUE str) https://github.com/ruby/ruby/blob/trunk/compile.c#L8269
     const rb_iseq_t *iseq;
     VALUE loader_obj = TypedData_Make_Struct(0, struct ibf_load, &ibf_load_type, load);
 
-    ibf_setup_load(load, loader_obj, str);
+    ibf_load_setup(load, loader_obj, str);
     iseq = ibf_load_iseq(load, 0);
 
     RB_GC_GUARD(loader_obj);
@@ -8265,7 +8283,7 @@ iseq_ibf_load_extra_data(VALUE str) https://github.com/ruby/ruby/blob/trunk/compile.c#L8283
     VALUE loader_obj = TypedData_Make_Struct(0, struct ibf_load, &ibf_load_type, load);
     VALUE extra_str;
 
-    ibf_setup_load(load, loader_obj, str);
+    ibf_load_setup(load, loader_obj, str);
     extra_str = rb_str_new2(load->buff + load->header->extra_size);
     RB_GC_GUARD(loader_obj);
     return extra_str;

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

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