19
19
#include "php_soap.h"
20
20
#include "ext/hash/php_hash.h" /* For php_hash_bin2hex() */
21
21
22
- static char * get_http_header_value_nodup (char * headers , char * type , size_t * len );
22
+ static const char * get_http_header_value_nodup (const char * headers , size_t headers_len , const char * type , size_t type_len , size_t * len );
23
23
static char * get_http_header_value (zend_string * headers , char * type );
24
24
static zend_string * get_http_body (php_stream * stream , bool close , zend_string * headers );
25
25
static zend_string * get_http_headers (php_stream * stream );
@@ -353,8 +353,7 @@ bool make_http_soap_request(
353
353
int use_proxy = 0 ;
354
354
int use_ssl ;
355
355
zend_string * http_body ;
356
- char * content_type , * http_version , * cookie_itt ;
357
- size_t cookie_len ;
356
+ char * content_type , * http_version ;
358
357
bool http_close ;
359
358
zend_string * http_headers ;
360
359
char * connection ;
@@ -1013,34 +1012,36 @@ bool make_http_soap_request(
1013
1012
we shouldn't be changing urls so path doesn't
1014
1013
matter too much
1015
1014
*/
1016
- cookie_itt = ZSTR_VAL (http_headers );
1015
+ const char * cookie_itt = ZSTR_VAL (http_headers );
1016
+ size_t cookie_len = ZSTR_LEN (http_headers );
1017
+ size_t parsed_cookie_len ;
1017
1018
1018
- while ((cookie_itt = get_http_header_value_nodup (cookie_itt , "Set-Cookie:" , & cookie_len ))) {
1019
+ while ((cookie_itt = get_http_header_value_nodup (cookie_itt , cookie_len , ZEND_STRL ( "Set-Cookie:" ) , & parsed_cookie_len ))) {
1019
1020
zval * cookies = Z_CLIENT_COOKIES_P (this_ptr );
1020
1021
SEPARATE_ARRAY (cookies );
1021
1022
1022
- char * cookie = estrndup (cookie_itt , cookie_len );
1023
+ char * cookie = estrndup (cookie_itt , parsed_cookie_len );
1023
1024
char * eqpos = strstr (cookie , "=" );
1024
1025
char * sempos = strstr (cookie , ";" );
1025
1026
if (eqpos != NULL && (sempos == NULL || sempos > eqpos )) {
1026
1027
smart_str name = {0 };
1027
- int cookie_len ;
1028
+ size_t current_cookie_len ;
1028
1029
zval zcookie ;
1029
1030
1030
1031
if (sempos != NULL ) {
1031
- cookie_len = sempos - (eqpos + 1 );
1032
+ current_cookie_len = sempos - (eqpos + 1 );
1032
1033
} else {
1033
- cookie_len = strlen ( cookie ) - (eqpos - cookie )- 1 ;
1034
+ current_cookie_len = parsed_cookie_len - (eqpos - cookie )- 1 ;
1034
1035
}
1035
1036
1036
1037
smart_str_appendl (& name , cookie , eqpos - cookie );
1037
1038
smart_str_0 (& name );
1038
1039
1039
1040
array_init (& zcookie );
1040
- add_index_stringl (& zcookie , 0 , eqpos + 1 , cookie_len );
1041
+ add_index_stringl (& zcookie , 0 , eqpos + 1 , current_cookie_len );
1041
1042
1042
1043
if (sempos != NULL ) {
1043
- char * options = cookie + cookie_len + 1 ;
1044
+ char * options = cookie + current_cookie_len + 1 ;
1044
1045
while (* options ) {
1045
1046
while (* options == ' ' ) {options ++ ;}
1046
1047
sempos = strstr (options , ";" );
@@ -1076,7 +1077,8 @@ bool make_http_soap_request(
1076
1077
smart_str_free (& name );
1077
1078
}
1078
1079
1079
- cookie_itt = cookie_itt + cookie_len ;
1080
+ cookie_itt = cookie_itt + parsed_cookie_len ;
1081
+ cookie_len -= parsed_cookie_len ;
1080
1082
efree (cookie );
1081
1083
}
1082
1084
@@ -1387,24 +1389,22 @@ bool make_http_soap_request(
1387
1389
return true;
1388
1390
}
1389
1391
1390
- static char * get_http_header_value_nodup (char * headers , char * type , size_t * len )
1392
+ static const char * get_http_header_value_nodup (const char * headers , size_t headers_len , const char * type , size_t type_len , size_t * len )
1391
1393
{
1392
- char * pos , * tmp = NULL ;
1393
- int typelen , headerslen ;
1394
+ const char * pos ;
1395
+ const char * tmp = NULL ;
1394
1396
1395
- typelen = strlen (type );
1396
- headerslen = strlen (headers );
1397
1397
1398
1398
/* header `titles' can be lower case, or any case combination, according
1399
1399
* to the various RFC's. */
1400
1400
pos = headers ;
1401
1401
do {
1402
1402
/* start of buffer or start of line */
1403
- if (strncasecmp (pos , type , typelen ) == 0 ) {
1404
- char * eol ;
1403
+ if (strncasecmp (pos , type , type_len ) == 0 ) {
1404
+ const char * eol ;
1405
1405
1406
1406
/* match */
1407
- tmp = pos + typelen ;
1407
+ tmp = pos + type_len ;
1408
1408
1409
1409
/* strip leading whitespace */
1410
1410
while (* tmp == ' ' || * tmp == '\t' ) {
@@ -1413,7 +1413,7 @@ static char *get_http_header_value_nodup(char *headers, char *type, size_t *len)
1413
1413
1414
1414
eol = strchr (tmp , '\n' );
1415
1415
if (eol == NULL ) {
1416
- eol = headers + headerslen ;
1416
+ eol = headers + headers_len ;
1417
1417
} else if (eol > tmp ) {
1418
1418
if (* (eol - 1 ) == '\r' ) {
1419
1419
eol -- ;
@@ -1443,9 +1443,7 @@ static char *get_http_header_value_nodup(char *headers, char *type, size_t *len)
1443
1443
static char * get_http_header_value (zend_string * headers , char * type )
1444
1444
{
1445
1445
size_t len ;
1446
- char * value ;
1447
-
1448
- value = get_http_header_value_nodup (ZSTR_VAL (headers ), type , & len );
1446
+ const char * value = get_http_header_value_nodup (ZSTR_VAL (headers ), ZSTR_LEN (headers ), type , strlen (type ), & len );
1449
1447
1450
1448
if (value ) {
1451
1449
return estrndup (value , len );
0 commit comments