Skip to content
Permalink
Browse files

Merge pull request #849 from kachick/guard-segfault-from-sleep

Guard Kernel#sleep with nil or String arguments from segfault
  • Loading branch information
alex committed Dec 6, 2015
2 parents c2c5a3b + f3b68c5 commit 019daf03d75e32124c2dfd282915b49c35f27289
Showing with 10 additions and 1 deletion.
  1. +7 −0 tests/modules/test_kernel.py
  2. +3 −1 topaz/modules/kernel.py
@@ -217,6 +217,13 @@ def test_sleep(self, space):
assert space.int_w(w_res) == 0
assert time.time() - now >= 0.002

with self.raises(space, "TypeError"):
space.execute("return sleep nil")
with self.raises(space, "TypeError"):
space.execute("return sleep '1'")
with self.raises(space, "TypeError"):
space.execute("return sleep Object.new")

def test_trust(self, space):
w_res = space.execute("return 'a'.untrusted?")
assert self.unwrap(space, w_res) is False
@@ -341,8 +341,10 @@ def method_clone(self, space):
def method_sleep(self, space, w_duration=None):
if w_duration is None:
raise space.error(space.w_NotImplementedError)
elif space.is_kind_of(w_duration, space.w_string):
raise space.error(space.w_TypeError, "can't convert String into time interval")
start = time.time()
time.sleep(space.float_w(w_duration))
time.sleep(Coerce.float(space, w_duration))
return space.newint(int(round_double(time.time() - start, 0)))

@moduledef.method("initialize_clone")

0 comments on commit 019daf0

Please sign in to comment.
You can’t perform that action at this time.