php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7359 php_read() function works bad
Submitted: 2000-10-20 02:05 UTC Modified: 2001-06-02 20:59 UTC
From: mmlynarcik at charmed dot sk Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.3pl1 OS: Slackware Linux 7.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 4 = ?
Subscribe to this entry?

 
 [2000-10-20 02:05 UTC] mmlynarcik at charmed dot sk
Here is correct function :

int php_read(int fd, void *buf, int maxlen)                                                                                         
{                                                                                                                                   
     char *t;                                                                                                                       
     int m = 0, n = 0;                                                                                                              
     int no_read = 0;                                                                                                               
                                                                                                                                    
     errno = 0;                                                                                                                     
     t = (char *) buf;                                                                                                              
     while (*t != '\n' && *t != '\r' && *t != '\0' && n < maxlen) {                                                                 
          m = read(fd, (void *) t, 1);                                                                                              
          if (m > 0) {                                                                                                              
               t++;                                                                                                                 
               n++;                                                                                                                 
          } else if (m == 0) {                                                                                                      
               no_read++;                                                                                                           
               if (no_read > 200) {                                                                                                 
                    errno = ECONNRESET;                                                                                             
                    return -1;                                                                                                      
               }                                                                                                                    
          }                                                                                                                         
          if (errno != 0 && errno != ESPIPE && errno != EAGAIN) {                                                                   
               return -1;                                                                                                           
          }                                                                                                                         
          errno = 0;                                                                                                                
     }                                                                                                                              
     return n;                                                                                                                      
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-02 20:59 UTC] sniper@php.net
This should be fixed with PHP 4.0.6, please try the 
latest release candidate:

http://www.php.net/~andi/php-4.0.6RC2.tar.gz

-Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC