summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-11 16:16:19 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-11 16:16:19 +0000
commite4d528752a1235f17f1622827f7cec693e34157a (patch)
treeb5ccf2d17f07be67b9b001c8278eb268dbbdf743 /time.c
parent089106508261787f7b43840b0249a1f9e1fea9a0 (diff)
merge revision(s) 42596,42597,42598,42599: [Backport #8795]
* time.c (time_mload): ignore invalid offset and zone. [ruby-core:56648] [Bug #8795] * time.c (time_mload): ignore auxiliary data, offset and zone, if invalid. [ruby-core:56648] [Bug #8795] * test/ruby/test_time.rb: use the in_timezone() helper and define it at the top with other helpers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@42912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/time.c b/time.c
index 2173fcda8e..ac76686f46 100644
--- a/time.c
+++ b/time.c
@@ -849,7 +849,8 @@ static VALUE time_utc_offset _((VALUE));
static int obj2int(VALUE obj);
static VALUE obj2vint(VALUE obj);
static int month_arg(VALUE arg);
-static void validate_utc_offset(VALUE utc_offset);
+static VALUE validate_utc_offset(VALUE utc_offset);
+static VALUE validate_zone_name(VALUE zone_name);
static void validate_vtm(struct vtm *vtm);
static int obj2subsecx(VALUE obj, VALUE *subsecx);
@@ -2672,11 +2673,19 @@ month_arg(VALUE arg)
return mon;
}
-static void
+static VALUE
validate_utc_offset(VALUE utc_offset)
{
if (le(utc_offset, INT2FIX(-86400)) || ge(utc_offset, INT2FIX(86400)))
rb_raise(rb_eArgError, "utc_offset out of range");
+ return utc_offset;
+}
+
+static VALUE
+validate_zone_name(VALUE zone_name)
+{
+ StringValueCStr(zone_name);
+ return zone_name;
}
static void
@@ -4790,8 +4799,9 @@ time_mload(VALUE time, VALUE str)
get_attr(nano_num, {});
get_attr(nano_den, {});
get_attr(submicro, {});
- get_attr(offset, validate_utc_offset(offset));
- get_attr(zone, {});
+ get_attr(offset, (offset = rb_rescue(validate_utc_offset, offset, NULL, Qnil)));
+ get_attr(zone, (zone = rb_rescue(validate_zone_name, zone, NULL, Qnil)));
+
#undef get_attr
rb_copy_generic_ivar(time, str);
@@ -4877,7 +4887,7 @@ end_submicro: ;
time_fixoff(time);
}
if (!NIL_P(zone)) {
- tobj->vtm.zone = StringValueCStr(zone);
+ tobj->vtm.zone = RSTRING_PTR(zone);
}
return time;