php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #61525
Patch 61525-bugfix.patch revision 2012-03-29 07:01 UTC by joe at joegillotti dot com

Patch 61525-bugfix.patch for SOAP related Bug #61525

Patch version 2012-03-29 07:01 UTC

Return to Bug #61525 | Download this patch
Patch Revisions:

Developer: joe@joegillotti.com

From 32dd18644dffbff34af2beb3ee59c556f27525d2 Mon Sep 17 00:00:00 2001
From: Joe Gillotti <joe@joegillotti.com>
Date: Thu, 29 Mar 2012 02:59:15 -0400
Subject: [PATCH] soap: make space after http header colon optional

With regards to bug #61525, the SOAP extension expects all HTTP header lines to
have a space following the colon, eg: Content-Length: 1234. This patch makes
that space optional.
---
 ext/soap/php_http.c |   50 ++++++++++++++++++++++++++++----------------------
 1 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c
index a156488..5c8a2b7 100644
--- a/ext/soap/php_http.c
+++ b/ext/soap/php_http.c
@@ -189,7 +189,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph
 	old_error_reporting = EG(error_reporting);
 	EG(error_reporting) &= ~(E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
 
-	namelen = spprintf(&name, 0, "%s://%s:%d", (use_ssl && !*use_proxy)? "ssl" : "tcp", host, port);
+	namelen = spprintf(&name, 0, "%s://%s:%d", (use_ssl && !*use_proxy)? "ssl" :"tcp", host, port);
 
 	stream = php_stream_xport_create(name, namelen,
 		REPORT_ERRORS,
@@ -211,7 +211,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph
 		smart_str_appendc(&soap_headers, ':');
 		smart_str_append_unsigned(&soap_headers, phpurl->port);
 		smart_str_append_const(&soap_headers, " HTTP/1.1\r\n");
-		smart_str_append_const(&soap_headers, "Host: ");
+		smart_str_append_const(&soap_headers, "Host:");
 		smart_str_appends(&soap_headers, phpurl->host);
 		if (phpurl->port != 80) {
 			smart_str_appendc(&soap_headers, ':');
@@ -501,7 +501,7 @@ try_again:
 		} else {
 			smart_str_append_const(&soap_headers, " HTTP/1.0\r\n");
 		}
-		smart_str_append_const(&soap_headers, "Host: ");
+		smart_str_append_const(&soap_headers, "Host:");
 		smart_str_appends(&soap_headers, phpurl->host);
 		if (phpurl->port != (use_ssl?443:80)) {
 			smart_str_appendc(&soap_headers, ':');
@@ -519,7 +519,7 @@ try_again:
 		if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_user_agent", sizeof("_user_agent"), (void **)&tmp) == SUCCESS &&
 		    Z_TYPE_PP(tmp) == IS_STRING) {
 			if (Z_STRLEN_PP(tmp) > 0) {
-				smart_str_append_const(&soap_headers, "User-Agent: ");
+				smart_str_append_const(&soap_headers, "User-Agent:");
 				smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
 				smart_str_append_const(&soap_headers, "\r\n");
 			}
@@ -527,12 +527,12 @@ try_again:
 		           php_stream_context_get_option(context, "http", "user_agent", &tmp) == SUCCESS &&
 		           Z_TYPE_PP(tmp) == IS_STRING) {
 			if (Z_STRLEN_PP(tmp) > 0) {
-				smart_str_append_const(&soap_headers, "User-Agent: ");
+				smart_str_append_const(&soap_headers, "User-Agent:");
 				smart_str_appendl(&soap_headers, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
 				smart_str_append_const(&soap_headers, "\r\n");
 			}
 		} else if (FG(user_agent)) {
-			smart_str_append_const(&soap_headers, "User-Agent: ");
+			smart_str_append_const(&soap_headers, "User-Agent:");
 			smart_str_appends(&soap_headers, FG(user_agent));
 			smart_str_append_const(&soap_headers, "\r\n");
 		} else {
@@ -557,7 +557,7 @@ try_again:
 				smart_str_append_const(&soap_headers, "\"\r\n");
 			}
 		}
-		smart_str_append_const(&soap_headers,"Content-Length: ");
+		smart_str_append_const(&soap_headers,"Content-Length:");
 		smart_str_append_long(&soap_headers, request_size);
 		smart_str_append_const(&soap_headers, "\r\n");
 
@@ -751,7 +751,7 @@ try_again:
 			n = zend_hash_num_elements(Z_ARRVAL_PP(cookies));
 			if (n > 0) {
 				zend_hash_internal_pointer_reset(Z_ARRVAL_PP(cookies));
-				smart_str_append_const(&soap_headers, "Cookie: ");
+				smart_str_append_const(&soap_headers, "Cookie:");
 				for (i = 0; i < n; i++) {
 					zend_hash_get_current_data(Z_ARRVAL_PP(cookies), (void **)&data);
 					zend_hash_get_current_key(Z_ARRVAL_PP(cookies), &key, NULL, FALSE);
@@ -873,7 +873,7 @@ try_again:
 	   we shouldn't be changing urls so path dont
 	   matter too much
 	*/
-	cookie_itt = strstr(http_headers,"Set-Cookie: ");
+	cookie_itt = strstr(http_headers,"Set-Cookie:");
 	while (cookie_itt) {
 		char *end_pos, *cookie;
 		char *eqpos, *sempos;
@@ -887,7 +887,7 @@ try_again:
 		}
 
 		end_pos = strstr(cookie_itt,"\r\n");
-		cookie = get_http_header_value(cookie_itt,"Set-Cookie: ");
+		cookie = get_http_header_value(cookie_itt,"Set-Cookie:");
 
 		eqpos = strstr(cookie, "=");
 		sempos = strstr(cookie, ";");
@@ -945,7 +945,7 @@ try_again:
 			smart_str_free(&name);
 		}
 
-		cookie_itt = strstr(cookie_itt + sizeof("Set-Cookie: "), "Set-Cookie: ");
+		cookie_itt = strstr(cookie_itt + sizeof("Set-Cookie:"), "Set-Cookie:");
 		efree(cookie);
 	}
 
@@ -953,7 +953,7 @@ try_again:
 	if (http_1_1) {
 		http_close = FALSE;
 		if (use_proxy && !use_ssl) {
-			connection = get_http_header_value(http_headers,"Proxy-Connection: ");
+			connection = get_http_header_value(http_headers,"Proxy-Connection:");
 			if (connection) {
 				if (strncasecmp(connection, "close", sizeof("close")-1) == 0) {
 					http_close = TRUE;
@@ -962,7 +962,7 @@ try_again:
 			}
 		}
 		if (http_close == FALSE) {
-			connection = get_http_header_value(http_headers,"Connection: ");
+			connection = get_http_header_value(http_headers,"Connection:");
 			if (connection) {
 				if (strncasecmp(connection, "close", sizeof("close")-1) == 0) {
 					http_close = TRUE;
@@ -973,7 +973,7 @@ try_again:
 	} else {
 		http_close = TRUE;
 		if (use_proxy && !use_ssl) {
-			connection = get_http_header_value(http_headers,"Proxy-Connection: ");
+			connection = get_http_header_value(http_headers,"Proxy-Connection:");
 			if (connection) {
 				if (strncasecmp(connection, "Keep-Alive", sizeof("Keep-Alive")-1) == 0) {
 					http_close = FALSE;
@@ -982,7 +982,7 @@ try_again:
 			}
 		}
 		if (http_close == TRUE) {
-			connection = get_http_header_value(http_headers,"Connection: ");
+			connection = get_http_header_value(http_headers,"Connection:");
 			if (connection) {
 				if (strncasecmp(connection, "Keep-Alive", sizeof("Keep-Alive")-1) == 0) {
 					http_close = FALSE;
@@ -1019,7 +1019,7 @@ try_again:
 	if (http_status >= 300 && http_status < 400) {
 		char *loc;
 
-		if ((loc = get_http_header_value(http_headers,"Location: ")) != NULL) {
+		if ((loc = get_http_header_value(http_headers,"Location:")) != NULL) {
 			php_url *new_url  = php_url_parse(loc);
 
 			if (new_url != NULL) {
@@ -1065,7 +1065,7 @@ try_again:
 	} else if (http_status == 401) {
 		/* Digest authentication */
 		zval **digest, **login, **password;
-		char *auth = get_http_header_value(http_headers, "WWW-Authenticate: ");
+		char *auth = get_http_header_value(http_headers, "WWW-Authenticate:");
 
 		if (auth &&
 				strstr(auth, "Digest") == auth &&
@@ -1142,7 +1142,7 @@ try_again:
 	smart_str_free(&soap_headers_z);
 
 	/* Check and see if the server even sent a xml document */
-	content_type = get_http_header_value(http_headers,"Content-Type: ");
+	content_type = get_http_header_value(http_headers,"Content-Type:");
 	if (content_type) {
 		char *pos = NULL;
 		int cmplen;
@@ -1172,7 +1172,7 @@ try_again:
 	}
 
 	/* Decompress response */
-	content_encoding = get_http_header_value(http_headers,"Content-Encoding: ");
+	content_encoding = get_http_header_value(http_headers,"Content-Encoding:");
 	if (content_encoding) {
 		zval func;
 		zval retval;
@@ -1282,6 +1282,12 @@ static char *get_http_header_value(char *headers, char *type)
 			} else if (eol > tmp && *(eol-1) == '\r') {
 				eol--;
 			}
+
+			/* allow for optional extra space after colon */
+			if (*tmp == ' ') {
+				tmp++;
+			}
+
 			return estrndup(tmp, eol - tmp);
 		}
 
@@ -1302,18 +1308,18 @@ static int get_http_body(php_stream *stream, int close, char *headers,  char **r
 	int header_close = close, header_chunked = 0, header_length = 0, http_buf_size = 0;
 
 	if (!close) {
-		header = get_http_header_value(headers, "Connection: ");
+		header = get_http_header_value(headers, "Connection:");
 		if (header) {
 			if(!strncasecmp(header, "close", sizeof("close")-1)) header_close = 1;
 			efree(header);
 		}
 	}
-	header = get_http_header_value(headers, "Transfer-Encoding: ");
+	header = get_http_header_value(headers, "Transfer-Encoding:");
 	if (header) {
 		if(!strncasecmp(header, "chunked", sizeof("chunked")-1)) header_chunked = 1;
 		efree(header);
 	}
-	header = get_http_header_value(headers, "Content-Length: ");
+	header = get_http_header_value(headers, "Content-Length:");
 	if (header) {
 		header_length = atoi(header);
 		efree(header);
-- 
1.7.9.1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC