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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mmlynarcik at charmed dot sk
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Sat Dec 21 12:01:31 2024 UTC