]> 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)
ext/standard/basic_functions.c
ext/standard/tests/time/bug60222.phpt [new file with mode: 0644]

index c036ad9fc85aa016673fcfe904de7510daf20571..528e4f65b96e64eaa9ddaa424b5691329fa4feea 100644 (file)
@@ -4467,6 +4467,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===