php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6913 wrong use of C language, serious bug!
Submitted: 2000-09-27 21:47 UTC Modified: 2000-10-02 13:26 UTC
From: melchers at cis dot fu-berlin dot de Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.2 OS: IRIX-6.x
Private report: No CVE-ID: None
 [2000-09-27 21:47 UTC] melchers at cis dot fu-berlin dot de
file ext/standard/file.c contains the line:
        if ((*buf = FP_FGETC(socketd, (FILE*)what, issock)) == EOF) {
this is a _serious_ bug, since on _all_ machine architectures where the data type
 "char" defaults to unsigned, the return value of FP_FGETC() is converted to
unsigned, before it is compared to EOF. Since EOF is defined as (-1), the
comparison _never_ succedds. This makes any usage of sockets and file-I/O
on "unsigned char" architectures impossible. As far as i remember, the bug
occurs in all php versions, i.e. 3.x and 4.x.

my page for fgetc(3) says:

WARNING
     If the integer value returned by getc, getchar, or fgetc is stored into a
     character variable and then compared against the integer constant EOF,
     the comparison may never succeed, because sign-extension of a character
     on widening to integer is machine-dependent.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-27 22:55 UTC] melchers at cis dot fu-berlin dot de
i don't find this line in the php-3.x series,
although socket communication is not possible
in irix: fgets() never returns as long as
the other side keeps the socket open and
php is blocked by waiting for data.
The above error can trivially fixed by writing:
int ii;
if ((ii = FP_FGETC(socketd, (FILE*)what, issock)) == EOF) {
  *buf = ii;
  ...
} else {
  *buf = ii;
  ...
}

 [2000-09-29 20:16 UTC] melchers at cis dot fu-berlin dot de
my last explanation is a bit unclear, sorry!
with all php-3.0.x versions, i have the
following problem with socket usage and php:
When the socket connection is established,
i.e. between the php-Script(client) and a
mail server, the php script could _only_
receive
data, when the data written by the server
are already received by the client OS protocol
stack. Otherwise, i.e. when the client
tries to read (blocking or unblocking) data,
the fgets() function _never returns data.
Even if the data packets from the server
side of the socket arrives one second later,
fgets() never return any byte more.
Using blocking reads: the function fgets()
returns never.
Using unblocking reads: the function fgets()
never returns any byte.

Perhaps the handling of EOF in fgets()
is a problem. Perhaps a signed/unsigned
problem? Ok, i have to read the manual of
my debugger...

 [2000-10-02 13:26 UTC] sterling@php.net
fixed in CVS
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC