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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC