Skip to content

ext/soap: Compare Set-Cookie header case-insensitively #6143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ext/standard/md5.h"
#include "ext/standard/php_random.h"

static char *get_http_header_value_nodup(char *headers, char *type, size_t *len);
static char *get_http_header_value(char *headers, char *type);
static zend_string *get_http_body(php_stream *socketd, int close, char *headers);
static zend_string *get_http_headers(php_stream *socketd);
Expand Down Expand Up @@ -350,6 +351,7 @@ int make_http_soap_request(zval *this_ptr,
int use_ssl;
zend_string *http_body;
char *content_type, *http_version, *cookie_itt;
size_t cookie_len;
int http_close;
zend_string *http_headers;
char *connection;
Expand Down Expand Up @@ -968,8 +970,9 @@ int make_http_soap_request(zval *this_ptr,
we shouldn't be changing urls so path doesn't
matter too much
*/
cookie_itt = strstr(ZSTR_VAL(http_headers), "Set-Cookie: ");
while (cookie_itt) {
cookie_itt = ZSTR_VAL(http_headers);

while ((cookie_itt = get_http_header_value_nodup(cookie_itt, "Set-Cookie: ", &cookie_len))) {
char *cookie;
char *eqpos, *sempos;
zval *cookies;
Expand All @@ -981,7 +984,7 @@ int make_http_soap_request(zval *this_ptr,
cookies = zend_hash_str_update(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1, &tmp_cookies);
}

cookie = get_http_header_value(cookie_itt,"Set-Cookie: ");
cookie = estrndup(cookie_itt, cookie_len);

eqpos = strstr(cookie, "=");
sempos = strstr(cookie, ";");
Expand Down Expand Up @@ -1039,7 +1042,7 @@ int make_http_soap_request(zval *this_ptr,
smart_str_free(&name);
}

cookie_itt = strstr(cookie_itt + sizeof("Set-Cookie: "), "Set-Cookie: ");
cookie_itt = cookie_itt + cookie_len;
efree(cookie);
}

Expand Down Expand Up @@ -1357,7 +1360,7 @@ int make_http_soap_request(zval *this_ptr,
return TRUE;
}

static char *get_http_header_value(char *headers, char *type)
static char *get_http_header_value_nodup(char *headers, char *type, size_t *len)
{
char *pos, *tmp = NULL;
int typelen, headerslen;
Expand Down Expand Up @@ -1394,7 +1397,9 @@ static char *get_http_header_value(char *headers, char *type)
eol--;
}
}
return estrndup(tmp, eol - tmp);

*len = eol - tmp;
return tmp;
}

/* find next line */
Expand All @@ -1408,6 +1413,20 @@ static char *get_http_header_value(char *headers, char *type)
return NULL;
}

static char *get_http_header_value(char *headers, char *type)
{
size_t len;
char *value;

value = get_http_header_value_nodup(headers, type, &len);

if (value) {
return estrndup(value, len);
}

return NULL;
}

static zend_string* get_http_body(php_stream *stream, int close, char *headers)
{
zend_string *http_buf = NULL;
Expand Down