summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 15:14:55 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 15:14:55 +0000
commitd0d0898c0ac29fa6debf0fa0e18844e83a63f831 (patch)
treec3cb1a2a85cbb1c8b05ae5c3f82518d3b6b0cd58
parentbb4d72c51f9c7233c2d3b54c4fc1359557f3482d (diff)
* compile.c (ibf_setup_load): rename to ibf_load_setup().
* compile.c (iseq_load_setup): check binary format. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--compile.c24
2 files changed, 27 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b790d4c7a86..d019eb32ca2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Dec 9 00:13:09 2015 Koichi Sasada <ko1@atdot.net>
+
+ * 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@gmail.com>
* test/io/console/test_io_console.rb (run_pty): Avoid waiting twice
diff --git a/compile.c b/compile.c
index bbdfcf8e49a..1f4f649e7d6 100644
--- a/compile.c
+++ b/compile.c
@@ -8193,8 +8193,11 @@ ibf_load_iseq(const struct ibf_load *load, const rb_iseq_t *index_iseq)
}
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, VALUE loader_obj, VALUE str)
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)
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)
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;