Permalink
Browse files

Fix null pointer dereference in mrb_time_initialize

  • Loading branch information...
bouk committed Nov 16, 2016
1 parent 743c1e7 commit b7f9a58757bdf30e9d64191ac47d81144e3f6098
Showing with 13 additions and 2 deletions.
  1. +2 −2 mrbgems/mruby-time/src/time.c
  2. +11 −0 mrbgems/mruby-time/test/time.rb
@@ -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 @@
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

0 comments on commit b7f9a58

Please sign in to comment.