#41516 [Opn->Csd]: fgets() returns a line of text when length parameter is <= 0
| From: | tony2001@php.net | Date: | Tue, 29 May 2007 20:48:42 +0000 |
| Subject: | #41516 [Opn->Csd]: fgets() returns a line of text when length parameter is <= 0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113168@lists.php.net to get a copy of this message | ||
ID: 41516
Updated by: tony2001@php.net
Reported By: kraghuba at in dot ibm dot com
-Status: Open
+Status: Closed
Bug Type: Filesystem function related
Operating System: Windows XP, Linux
PHP Version: 6CVS-2007-05-28 (CVS)
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-05-28 05:08:24] kraghuba at in dot ibm dot com
Description:
------------
fgets() functions returns a line of text form file when length
parameter is <= 0.
fgets() should return a warning message indicating that "length
parameter should be greater than 0" but returns a line of text when
length parameter is <= 0
This failure is only applicable to PHP 6.
Consider adding a check for length parameter in the code after
paramerts are parsed.
if (len <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be
greater than 0");
RETURN_FALSE;
}
Reproduce code:
---------------
<?php
$fp = fopen(__FILE__, "r");
var_dump( fgets($fp, 0) );
var_dump( fgets($fp, -10) );
fclose($fp);
?>
Expected result:
----------------
Warning: fgets(): Length parameter must be greater than 0 in %s on line
%d
bool(false)
Warning: fgets(): Length parameter must be greater than 0 in %s on line
%d
bool(false)
Actual result:
--------------
string(7) "<?php
"
string(31) " $fp = fopen(__FILE__, "r");
"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41516&edit=1