]> granicus.if.org Git - php/commitdiff
Fixed bug #60222 (time_nanosleep() does validate input params).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 12 Mar 2012 16:53:07 +0000 (16:53 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 12 Mar 2012 16:53:07 +0000 (16:53 +0000)
NEWS
ext/standard/basic_functions.c
ext/standard/tests/time/bug60222.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 331814435513bc7ddc4d31bc19372bddfee17c03..a0acb438363f985e5bb1ab9b18b340f3f4dbd278 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ PHP                                                                        NEWS
   . Fixed bug #60569 (Nullbyte truncates Exception $message). (Ilia)
   . Fixed bug #60227 (header() cannot detect the multi-line header with CR).
     (rui, Gustavo)
+  . Fixed bug #60222 (time_nanosleep() does validate input params). (Ilia)
   . Fixed bug #52719 (array_walk_recursive crashes if third param of the
     function is by reference). (Nikita Popov)
   . Fixed bug #51860 (Include fails with toplevel symlink to /). (Dmitry)
index 91ec37b32c29faf2883f6da4de20112dbf6dc264..99831a1f42115d71d33473b8f26811277d3a4b0f 100644 (file)
@@ -4497,6 +4497,15 @@ PHP_FUNCTION(time_nanosleep)
                return;
        }
 
+       if (tv_sec < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The seconds value must be greater than 0");
+               RETURN_FALSE;
+       }
+       if (tv_nsec < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The nanoseconds value must be greater than 0");
+               RETURN_FALSE;
+       }
+
        php_req.tv_sec = (time_t) tv_sec;
        php_req.tv_nsec = tv_nsec;
        if (!nanosleep(&php_req, &php_rem)) {
diff --git a/ext/standard/tests/time/bug60222.phpt b/ext/standard/tests/time/bug60222.phpt
new file mode 100644 (file)
index 0000000..8053a81
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #60222 (time_nanosleep() does validate input params)
+--FILE--
+<?php
+       var_dump(time_nanosleep(-1, 0));
+       var_dump(time_nanosleep(0, -1));
+?>
+===DONE===
+--EXPECTF--
+Warning: time_nanosleep(): The seconds value must be greater than 0 in %s on line %d
+bool(false)
+
+Warning: time_nanosleep(): The nanoseconds value must be greater than 0 in %s on line %d
+bool(false)
+===DONE===