iliaa                                    Mon, 13 Dec 2010 16:53:26 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=306342

Log:
Fixed bug #48607 (fwrite() doesn't check reply from ftp server before exiting)

Bug: http://bugs.php.net/48607 (Verified) fwrite() doesn't check reply from ftp 
server before exiting
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c
    U   php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-12-13 14:29:42 UTC (rev 306341)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-12-13 16:53:26 UTC (rev 306342)
@@ -10,6 +10,8 @@
 - Core:
   . Fixed bug #48484 (array_product() always returns 0 for an empty array).
     (Ilia)
+  . Fixed bug #48607 (fwrite() doesn't check reply from ftp server before
+    exiting). (Ilia)

 - Filter extension:
   . Fixed bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges).

Modified: php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c       
2010-12-13 14:29:42 UTC (rev 306341)
+++ php/php-src/branches/PHP_5_3/ext/standard/ftp_fopen_wrapper.c       
2010-12-13 16:53:26 UTC (rev 306342)
@@ -98,13 +98,33 @@
 static int php_stream_ftp_stream_close(php_stream_wrapper *wrapper, php_stream 
*stream TSRMLS_DC)
 {
        php_stream *controlstream = (php_stream *)stream->wrapperdata;
+       int ret = 0;

        if (controlstream) {
+               if (strpbrk(stream->mode, "wa+")) {
+                       char tmp_line[512];
+                       int result;
+
+                       /* For write modes close data stream first to signal 
EOF to server */
+                       stream->wrapperdata = NULL;
+                       php_stream_close(stream);
+                       stream = NULL;
+
+                       result = GET_FTP_RESULT(controlstream);
+                       if (result != 226 && result != 250) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"FTP server error %d:%s", result, tmp_line);
+                               ret = EOF;
+                       }
+               }
+
                php_stream_write_string(controlstream, "QUIT\r\n");
                php_stream_close(controlstream);
-               stream->wrapperdata = NULL;
+               if (stream) {
+                       stream->wrapperdata = NULL;
+               }
        }
-       return 0;
+
+       return ret;
 }
 /* }}} */


Modified: php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c
===================================================================
--- php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c  2010-12-13 14:29:42 UTC 
(rev 306341)
+++ php/php-src/trunk/ext/standard/ftp_fopen_wrapper.c  2010-12-13 16:53:26 UTC 
(rev 306342)
@@ -98,13 +98,33 @@
 static int php_stream_ftp_stream_close(php_stream_wrapper *wrapper, php_stream 
*stream TSRMLS_DC)
 {
        php_stream *controlstream = (php_stream *)stream->wrapperdata;
+       int ret = 0;

        if (controlstream) {
+               if (strpbrk(stream->mode, "wa+")) {
+                       char tmp_line[512];
+                       int result;
+
+                       /* For write modes close data stream first to signal 
EOF to server */
+                       stream->wrapperdata = NULL;
+                       php_stream_close(stream);
+                       stream = NULL;
+
+                       result = GET_FTP_RESULT(controlstream);
+                       if (result != 226 && result != 250) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"FTP server error %d:%s", result, tmp_line);
+                               ret = EOF;
+                       }
+               }
+
                php_stream_write_string(controlstream, "QUIT\r\n");
                php_stream_close(controlstream);
-               stream->wrapperdata = NULL;
+               if (stream) {
+                       stream->wrapperdata = NULL;
+               }
        }
-       return 0;
+
+       return ret;
 }
 /* }}} */


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to