Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: 
Changeset: r93352:543c4e0c83b1
Date: 2017-12-10 22:11 +0100
http://bitbucket.org/pypy/pypy/changeset/543c4e0c83b1/

Log:    don't crash when calling sleep with inf or nan

        (see https://www.blackhat.com/docs/eu-17/materials/eu-17-Arnaboldi-
        Exposing-Hidden-Exploitable-Behaviors-In-Programming-Languages-
        Using-Differential-Fuzzing-wp.pdf even though I am sure it is not
        really exploitable)

diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -310,12 +310,19 @@
     errno = rposix.get_saved_errno()
     return os.strerror(errno)
 
+def _check_sleep_arg(space, secs):
+    from rpython.rlib.rfloat import isinf, isnan
+    if secs < 0:
+        raise oefmt(space.w_IOError,
+                    "Invalid argument: negative time in sleep")
+    if isinf(secs) or isnan(secs):
+        raise oefmt(space.w_IOError,
+                    "Invalid argument: inf or nan")
+
 if sys.platform != 'win32':
     @unwrap_spec(secs=float)
     def sleep(space, secs):
-        if secs < 0:
-            raise oefmt(space.w_IOError,
-                        "Invalid argument: negative time in sleep")
+        _check_sleep_arg(space, secs)
         rtime.sleep(secs)
 else:
     from rpython.rlib import rwin32
@@ -336,9 +343,7 @@
                                    OSError(EINTR, "sleep() interrupted"))
     @unwrap_spec(secs=float)
     def sleep(space, secs):
-        if secs < 0:
-            raise oefmt(space.w_IOError,
-                        "Invalid argument: negative time in sleep")
+        _check_sleep_arg(space, secs)
         # as decreed by Guido, only the main thread can be
         # interrupted.
         main_thread = space.fromcache(State).main_thread
diff --git a/pypy/module/time/test/test_time.py 
b/pypy/module/time/test/test_time.py
--- a/pypy/module/time/test/test_time.py
+++ b/pypy/module/time/test/test_time.py
@@ -19,6 +19,8 @@
         raises(TypeError, time.sleep, "foo")
         time.sleep(0.12345)
         raises(IOError, time.sleep, -1.0)
+        raises(IOError, time.sleep, float('nan'))
+        raises(IOError, time.sleep, float('inf'))
 
     def test_clock(self):
         import time
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to