dmitry          Tue Jul 24 09:28:12 2007 UTC

  Modified files:              
    /php-src/ext/soap   php_http.c 
  Log:
  Fixed bug #41983 (Error Fetching http headers terminated by '\n')
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/soap/php_http.c?r1=1.108&r2=1.109&diff_format=u
Index: php-src/ext/soap/php_http.c
diff -u php-src/ext/soap/php_http.c:1.108 php-src/ext/soap/php_http.c:1.109
--- php-src/ext/soap/php_http.c:1.108   Fri Jul 13 09:15:03 2007
+++ php-src/ext/soap/php_http.c Tue Jul 24 09:28:12 2007
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: php_http.c,v 1.108 2007/07/13 09:15:03 dmitry Exp $ */
+/* $Id: php_http.c,v 1.109 2007/07/24 09:28:12 dmitry Exp $ */
 
 #include "php_soap.h"
 #include "ext/standard/base64.h"
@@ -1155,17 +1155,19 @@
 
                        /* match */
                        tmp = pos + typelen;
-                       eol = strstr(tmp, "\r\n");
+                       eol = strchr(tmp, '\n');
                        if (eol == NULL) {
                                eol = headers + headerslen;
+                       } else if (eol > tmp && *(eol-1) == '\r') {
+                               eol--;
                        }
                        return estrndup(tmp, eol - tmp);
                }
 
                /* find next line */
-               pos = strstr(pos, "\r\n");
+               pos = strchr(pos, '\n');
                if (pos) {
-                       pos += 2;
+                       pos++;
                }
 
        } while (pos);
@@ -1205,7 +1207,7 @@
        }
 
        if (header_chunked) {
-               char done, chunk_size[10];
+               char ch, done, chunk_size[10], headerbuf[8192];
 
                done = FALSE;
 
@@ -1233,11 +1235,20 @@
                                                len_size += len_read;
                                                http_buf_size += len_read;
                                        }
-                               }
 
-                               /* Eat up '\r' '\n' */
-                               php_stream_getc(stream);
-                               php_stream_getc(stream);
+                                       /* Eat up '\r' '\n' */
+                                       ch = php_stream_getc(stream);
+                                       if (ch == '\r') {
+                                               ch = php_stream_getc(stream);
+                                       }
+                                       if (ch != '\n') {
+                                               /* Somthing wrong in chunked 
encoding */
+                                               if (http_buf) {
+                                                       efree(http_buf);
+                                               }
+                                               return FALSE;
+                                       }
+                               }
                        } else {
                                /* Somthing wrong in chunked encoding */
                                if (http_buf) {
@@ -1250,6 +1261,19 @@
                        }
                }
 
+               /* Ignore trailer headers */
+               while (1) {
+                       if (!php_stream_gets(stream, ZSTR(headerbuf), 
sizeof(headerbuf))) {
+                               break;
+                       }
+
+                       if ((headerbuf[0] == '\r' && headerbuf[1] == '\n') ||
+                           (headerbuf[0] == '\n')) {
+                               /* empty line marks end of headers */
+                               break;
+                       }
+               }
+
                if (http_buf == NULL) {
                        http_buf = emalloc(1);
                }
@@ -1296,7 +1320,8 @@
                        break;
                }
 
-               if (strcmp(headerbuf, "\r\n") == 0) {
+               if ((headerbuf[0] == '\r' && headerbuf[1] == '\n') ||
+                   (headerbuf[0] == '\n')) {
                        /* empty line marks end of headers */
                        done = TRUE;
                        break;

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

Reply via email to