X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_headers_api.c;h=a5448a995c1a79eb86c442795e9040db8d8a17e0;hb=e33c13f52c027e18fccbf47daa817f7d72518dfd;hp=c778662f5f2029cd36760c883e7fd98512882bc2;hpb=669d2e6a8bdc642b6b52693f4593f199ddd7e8d2;p=m6w6%2Fext-http diff --git a/http_headers_api.c b/http_headers_api.c index c778662..a5448a9 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -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; }