]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #27633 (Incorrect EOL translation by ftp_get() in ASCII
authorIlia Alshanetsky <iliaa@php.net>
Thu, 18 Mar 2004 17:15:47 +0000 (17:15 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 18 Mar 2004 17:15:47 +0000 (17:15 +0000)
mode).

NEWS
ext/ftp/ftp.c

diff --git a/NEWS b/NEWS
index 7838c7b61ee8d36060c8a26ae5051681bb05ff3d..475a49ac8731b84c24dfc23dbd27c48a838bb40f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,6 @@
 PHP 4                                                                      NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-?? Feb 2004, Version 4.3.5
+18 Mar 2004, Version 4.3.5RC4
 - Fixed possible crash using an invalid color index with a palette image in
   imagecolortransparent (Pierre)
 - Fixed php-cgi to not ignore command-line switches when run in a web context.
@@ -10,7 +10,9 @@ PHP 4                                                                      NEWS
   actually parsed. (Jon)
 - Fixed possible crashes inside socket extension, due to missing check inside
   allocation functions. (Ilia)
-- Fixed bug #27600 (GCC 3.0.4 does not like __attribute__ directive). (Ilia)
+- Fixed bug #27633 (Incorrect EOL translation by ftp_get() in ASCII mode).
+  (Ilia)
+- Fixed bug #27600 (GCC 3.0.4 does not like __attribute__ directive). (Sascha)
 - Fixed bug #27590 (crash during shutdown when freeing persistent resources
   in ZTS mode). (Ilia)
 - Fixed bug #27582 (possible crashes in imagefilltoborder()). (Pierre)
index 9d3468015a1d5f62e228de9cdbf7b58edf7fd24d..89aa74f03dd3f8a662ca96d9efe3587d2fc6fafe 100644 (file)
@@ -652,7 +652,6 @@ int
 ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, int resumepos)
 {
        databuf_t               *data = NULL;
-       char                    *ptr;
        int                     lastch;
        size_t                  rcvd;
        char                    arg[11];
@@ -703,12 +702,39 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
                }
 
                if (type == FTPTYPE_ASCII) {
-                       for (ptr = data->buf; rcvd; rcvd--, ptr++) {
-                               if (lastch == '\r' && *ptr != '\n')
+                       char *s;
+                       char *ptr = data->buf;
+                       char *e = ptr + rcvd;
+                       /* logic depends on the OS EOL
+                        * Win32 -> \r\n
+                        * Everything Else \n
+                        */
+#ifdef PHP_WIN32
+                       while ((s = strpbrk(ptr, "\r\n"))) {
+                               if (*s == '\n') {
                                        php_stream_putc(outstream, '\r');
-                               if (*ptr != '\r')
-                                       php_stream_putc(outstream, *ptr);
-                               lastch = *ptr;
+                               } else if (*s == '\r' && *(s + 1) == '\n') {
+                                       s++;
+                               }
+                               s++;
+                               php_stream_write(outstream, ptr, (s - ptr));
+                               if (*(s - 1) == '\r') {
+                                       php_stream_putc(outstream, '\n');
+                               }
+                               ptr = s;
+                       }
+#else 
+                       while ((s = memchr(ptr, '\r', (e - ptr)))) {
+                               php_stream_write(outstream, ptr, (s - ptr));
+                               if (*(s + 1) == '\n') {
+                                       s++;
+                               }
+                               php_stream_putc(outstream, '\n');
+                               ptr = s + 1;
+                       }
+#endif
+                       if (ptr < e) {
+                               php_stream_write(outstream, ptr, (e - ptr));
                        }
                }
                else {
@@ -717,9 +743,6 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
                }
        }
 
-       if (type == FTPTYPE_ASCII && lastch == '\r')
-               php_stream_putc(outstream, '\r');
-
        ftp->data = data = data_close(ftp, data);
 
        if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) {