ID:               26772
 Updated by:       [EMAIL PROTECTED]
 Reported By:      giovanni at giacobbi dot net
-Status:           Open
+Status:           Verified
-Bug Type:         Scripting Engine problem
+Bug Type:         Filesystem function related
 Operating System: Linux
-PHP Version:      4.3.4
+PHP Version:      4CVS, 5CVS


Previous Comments:
------------------------------------------------------------------------

[2004-01-02 22:20:00] giovanni at giacobbi dot net

ok ok, i got it. Follows a working patch.
Well, the patch is just a hack in my opinion, but.. hey, if there is a
"php_stream_from_zval_no_verify" macro it means you already hacked it
for something..
Maybe i haven't understood the API structure very well yet, but can
php_streams.h access directly zend_fetch_resource() without using a
zend_list.h macro?

--- php-4.3.4/ext/standard/file.c.orig  2003-10-10 03:38:01.000000000
+0200
+++ php-4.3.4/ext/standard/file.c       2004-01-03 04:08:04.000000000 +0100
@@ -1358,7 +1358,10 @@
                WRONG_PARAM_COUNT;
        }
 
-       php_stream_from_zval(stream, arg1);
+       /* we want our way to handle the error */
+       php_stream_from_zval_no_verify(stream, arg1);
+       if (!stream)
+               goto exit_failed;
 
        if (argc == 1) {
                /* ask streams to give us a buffer of an appropriate size */

------------------------------------------------------------------------

[2004-01-02 21:30:59] giovanni at giacobbi dot net

Description:
------------
See the example code. It should return FALSE according to the manual
(and to common good sense).

This is causing valid code like

while (($str = fgets($fd)) !== FALSE) {
  ...
}

to go into infinite loop, which is very bad.
I tried to look at the source code but it looks correct, as it  should
fall in file.c:1395, at the exit_failed label.


Reproduce code:
---------------
<?php

$fd = FALSE;

$retval = @fgets($fd);

var_dump($retval);


Expected result:
----------------
FALSE

Actual result:
--------------
NULL



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=26772&edit=1

Reply via email to