Commit f6663506 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #3295 from bouk/time-seg

Fix null pointer dereference in mrb_time_initialize
parents 0ee58a0f b7f9a587
......@@ -587,14 +587,14 @@ mrb_time_initialize(mrb_state *mrb, mrb_value self)
int n;
struct mrb_time *tm;
n = mrb_get_args(mrb, "|iiiiiii",
&ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
tm = (struct mrb_time*)DATA_PTR(self);
if (tm) {
mrb_free(mrb, tm);
}
mrb_data_init(self, NULL, &mrb_time_type);
n = mrb_get_args(mrb, "|iiiiiii",
&ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
if (n == 0) {
tm = current_mrb_time(mrb);
}
......
......@@ -211,3 +211,14 @@ assert('2000 times 500us make a second') do
end
t.usec == 0
end
assert("Time#initialize doens't leave uninitialized object accessible") do
assert_raise ArgumentError do
$x = Time.new
a = Object.new
def a.to_i
$x.mday
end
$x.initialize a
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment