php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41516 fgets() returns a line of text when length parameter is <= 0
Submitted: 2007-05-28 05:08 UTC Modified: 2007-05-29 20:48 UTC
From: kraghuba at in dot ibm dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 6CVS-2007-05-28 (CVS) OS: Windows XP, Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kraghuba at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-05-28 05:08 UTC] 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");
"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-29 20:48 UTC] tony2001@php.net
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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 09:01:34 2025 UTC