Skip to content

Commit

Permalink
Fixed bug #60222 (time_nanosleep() does validate input params).
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Alshanetsky committed Mar 12, 2012
1 parent 79a06bf commit 4cccba0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -87,6 +87,7 @@ PHP NEWS
- Standard:
. Fixed memory leak in substr_replace. (Pierrick)
. Make max_file_uploads ini directive settable outside of php.ini (Rasmus)
. Fixed bug #60222 (time_nanosleep() does validate input params). (Ilia)
. Fixed bug #60106 (stream_socket_server silently truncates long unix socket
paths). (Ilia)

Expand Down
9 changes: 9 additions & 0 deletions ext/standard/basic_functions.c
Expand Up @@ -4432,6 +4432,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)) {
Expand Down
15 changes: 15 additions & 0 deletions ext/standard/tests/time/bug60222.phpt
@@ -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===

0 comments on commit 4cccba0

Please sign in to comment.