php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1695 fgets read to few data (1 byte)
Submitted: 1999-07-11 23:39 UTC Modified: 1999-07-12 02:43 UTC
From: andreas dot rieber at tlc dot de Assigned:
Status: Closed Package: Other
PHP Version: 3.0.11 OS: Linux (different Types)
Private report: No CVE-ID: None
 [1999-07-11 23:39 UTC] andreas dot rieber at tlc dot de
<?
$fp = fsockopen( "localhost", 7); // echo port

fputs( $fp, "12345 this fail 67890\n"); // send data
$string = fgets( $fp, 3); // read first 3 bytes
echo "$string\n"; // echo them
$string = fgets( $fp, 100); // read to LF
echo "$string\n"; // echo

fclose($fp);
?>

With php3.0.9, php3.0.11 it reads only 2 bytes and than byte 3 to LF.

I fix one line and it will work!

functions/fsock.c
615c615
< 	amount = MIN(amount, maxlen - 1);
---
> 	amount = MIN(amount, maxlen); /*  - 1); */


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-07-12 02:43 UTC] sas at cvs dot php dot net
The observed behaviour is correct. From the Single Unix Specification:

char *fgets(char *s, int n, FILE *stream);

The fgets() function reads bytes from stream into the array pointed to by s, until n-1 bytes are read, or a newline character is read and transferred to s, or an        end-of-file condition is encountered. The string is then terminated with a null byte.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 01:01:28 2024 UTC