check length only when it's specified

add the same check to fgetss()
This commit is contained in:
Antony Dovgal 2007-05-30 09:16:29 +00:00
parent 56fcde4f4a
commit f90bb0e967

View file

@ -1135,10 +1135,10 @@ PHPAPI PHP_FUNCTION(fgets)
size_t retlen = 0;
if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &zstream, &length) == FAILURE) {
RETURN_NULL();
return;
}
if (length <= 0) {
if (ZEND_NUM_ARGS() == 2 && length <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
}
@ -1210,6 +1210,11 @@ PHPAPI PHP_FUNCTION(fgetss)
return;
}
if (ZEND_NUM_ARGS() >= 2 && length <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
RETURN_FALSE;
}
if (length == 1) {
/* For BC reasons, fgetss() should only return length-1 bytes. */
RETURN_FALSE;