- fix errenous bailout of http_parse_headers() introduced with last commit
[m6w6/ext-http] / http_headers_api.c
index c778662f5f2029cd36760c883e7fd98512882bc2..a5448a995c1a79eb86c442795e9040db8d8a17e0 100644 (file)
@@ -326,22 +326,15 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_
 PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *headers, zend_bool prettify, 
        http_info_callback callback_func, void **callback_data TSRMLS_DC)
 {
-       const char *colon = NULL, *line = NULL, *begin = header;
-       const char *body = http_locate_body(header);
-       size_t header_len;
+       const char *colon = NULL, *line = header;
        zval array;
-
-       INIT_ZARR(array, headers);
        
-       if (body) {
-               header_len = body - header;
-       } else {
-               header_len = strlen(header) + 1;
-       }
-       line = header;
+       INIT_ZARR(array, headers);
        
-       if (header_len) do {
+#define MORE_HEADERS (*(line-1) && !(*(line-1) == '\n' && (*line == '\n' || *line == '\r')))
+       do {
                int value_len = 0;
+               
                switch (*line++)
                {
                        case ':':
@@ -361,11 +354,8 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
                                                callback_func(callback_data, &headers, &i TSRMLS_CC);
                                                http_info_dtor(&i);
                                                Z_ARRVAL(array) = headers;
-                                       } else
-                                       
-                                       /* "header: value" pair */
-                                       if (colon) {
-
+                                       } else if (colon) {
+                                               /* "header: value" pair */
                                                /* skip empty key */
                                                if (header != colon) {
                                                        zval **previous = NULL;
@@ -403,6 +393,8 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
                                                        }
                                                        efree(key);
                                                }
+                                       } else if (MORE_HEADERS) {
+                                               return FAILURE;
                                        }
                                        colon = NULL;
                                        value_len = 0;
@@ -410,7 +402,7 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
                                }
                        break;
                }
-       } while (header_len > (size_t) (line - begin));
+       } while (MORE_HEADERS);
 
        return SUCCESS;
 }