Skip to content

Commit 304fb7a

Browse files
committed
Merge branch 'PHP-5.5' of git.php.net:/php-src into PHP-5.5
* 'PHP-5.5' of git.php.net:/php-src: Added type checks Added type checks
2 parents 860fc39 + b3ac352 commit 304fb7a

File tree

3 files changed

+64
-36
lines changed

3 files changed

+64
-36
lines changed

ext/soap/php_encoding.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,15 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
404404
encodePtr enc = NULL;
405405
HashTable *ht = Z_OBJPROP_P(data);
406406

407-
if (zend_hash_find(ht, "enc_type", sizeof("enc_type"), (void **)&ztype) == FAILURE) {
407+
if (zend_hash_find(ht, "enc_type", sizeof("enc_type"), (void **)&ztype) == FAILURE ||
408+
Z_TYPE_PP(ztype) != IS_LONG) {
408409
soap_error0(E_ERROR, "Encoding: SoapVar has no 'enc_type' property");
409410
}
410411

411-
if (zend_hash_find(ht, "enc_stype", sizeof("enc_stype"), (void **)&zstype) == SUCCESS) {
412-
if (zend_hash_find(ht, "enc_ns", sizeof("enc_ns"), (void **)&zns) == SUCCESS) {
412+
if (zend_hash_find(ht, "enc_stype", sizeof("enc_stype"), (void **)&zstype) == SUCCESS &&
413+
Z_TYPE_PP(zstype) == IS_STRING) {
414+
if (zend_hash_find(ht, "enc_ns", sizeof("enc_ns"), (void **)&zns) == SUCCESS &&
415+
Z_TYPE_PP(zns) == IS_STRING) {
413416
enc = get_encoder(SOAP_GLOBAL(sdl), Z_STRVAL_PP(zns), Z_STRVAL_PP(zstype));
414417
} else {
415418
zns = NULL;
@@ -445,19 +448,23 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
445448
}
446449

447450
if (style == SOAP_ENCODED || (SOAP_GLOBAL(sdl) && encode != enc)) {
448-
if (zend_hash_find(ht, "enc_stype", sizeof("enc_stype"), (void **)&zstype) == SUCCESS) {
449-
if (zend_hash_find(ht, "enc_ns", sizeof("enc_ns"), (void **)&zns) == SUCCESS) {
451+
if (zend_hash_find(ht, "enc_stype", sizeof("enc_stype"), (void **)&zstype) == SUCCESS &&
452+
Z_TYPE_PP(zstype) == IS_STRING) {
453+
if (zend_hash_find(ht, "enc_ns", sizeof("enc_ns"), (void **)&zns) == SUCCESS &&
454+
Z_TYPE_PP(zns) == IS_STRING) {
450455
set_ns_and_type_ex(node, Z_STRVAL_PP(zns), Z_STRVAL_PP(zstype));
451456
} else {
452457
set_ns_and_type_ex(node, NULL, Z_STRVAL_PP(zstype));
453458
}
454459
}
455460
}
456461

457-
if (zend_hash_find(ht, "enc_name", sizeof("enc_name"), (void **)&zname) == SUCCESS) {
462+
if (zend_hash_find(ht, "enc_name", sizeof("enc_name"), (void **)&zname) == SUCCESS &&
463+
Z_TYPE_PP(zname) == IS_STRING) {
458464
xmlNodeSetName(node, BAD_CAST(Z_STRVAL_PP(zname)));
459465
}
460-
if (zend_hash_find(ht, "enc_namens", sizeof("enc_namens"), (void **)&znamens) == SUCCESS) {
466+
if (zend_hash_find(ht, "enc_namens", sizeof("enc_namens"), (void **)&znamens) == SUCCESS &&
467+
Z_TYPE_PP(zname) == IS_STRING) {
461468
xmlNsPtr nsp = encode_add_ns(node, Z_STRVAL_PP(znamens));
462469
xmlSetNs(node, nsp);
463470
}
@@ -3640,18 +3647,21 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type TS
36403647
Z_OBJCE_PP(tmp) == soap_var_class_entry) {
36413648
zval **ztype;
36423649

3643-
if (zend_hash_find(Z_OBJPROP_PP(tmp), "enc_type", sizeof("enc_type"), (void **)&ztype) == FAILURE) {
3650+
if (zend_hash_find(Z_OBJPROP_PP(tmp), "enc_type", sizeof("enc_type"), (void **)&ztype) == FAILURE ||
3651+
Z_TYPE_PP(ztype) != IS_LONG) {
36443652
soap_error0(E_ERROR, "Encoding: SoapVar has no 'enc_type' property");
36453653
}
36463654
cur_type = Z_LVAL_PP(ztype);
36473655

3648-
if (zend_hash_find(Z_OBJPROP_PP(tmp), "enc_stype", sizeof("enc_stype"), (void **)&ztype) == SUCCESS) {
3656+
if (zend_hash_find(Z_OBJPROP_PP(tmp), "enc_stype", sizeof("enc_stype"), (void **)&ztype) == SUCCESS &&
3657+
Z_TYPE_PP(ztype) == IS_STRING) {
36493658
cur_stype = Z_STRVAL_PP(ztype);
36503659
} else {
36513660
cur_stype = NULL;
36523661
}
36533662

3654-
if (zend_hash_find(Z_OBJPROP_PP(tmp), "enc_ns", sizeof("enc_ns"), (void **)&ztype) == SUCCESS) {
3663+
if (zend_hash_find(Z_OBJPROP_PP(tmp), "enc_ns", sizeof("enc_ns"), (void **)&ztype) == SUCCESS &&
3664+
Z_TYPE_PP(ztype) == IS_STRING) {
36553665
cur_ns = Z_STRVAL_PP(ztype);
36563666
} else {
36573667
cur_ns = NULL;

ext/soap/php_http.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
3636
{
3737
zval **login, **password;
3838

39-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_login", sizeof("_proxy_login"), (void **)&login) == SUCCESS) {
39+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_login", sizeof("_proxy_login"), (void **)&login) == SUCCESS &&
40+
Z_TYPE_PP(login) == IS_STRING) {
4041
unsigned char* buf;
4142
int len;
4243
smart_str auth = {0};
4344

4445
smart_str_appendl(&auth, Z_STRVAL_PP(login), Z_STRLEN_PP(login));
4546
smart_str_appendc(&auth, ':');
46-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_password", sizeof("_proxy_password"), (void **)&password) == SUCCESS) {
47+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_password", sizeof("_proxy_password"), (void **)&password) == SUCCESS &&
48+
Z_TYPE_PP(password) == IS_STRING) {
4749
smart_str_appendl(&auth, Z_STRVAL_PP(password), Z_STRLEN_PP(password));
4850
}
4951
smart_str_0(&auth);
@@ -64,14 +66,16 @@ int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
6466
zval **login, **password;
6567

6668
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_login", sizeof("_login"), (void **)&login) == SUCCESS &&
67-
!zend_hash_exists(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest"))) {
69+
Z_TYPE_PP(login) == IS_STRING &&
70+
!zend_hash_exists(Z_OBJPROP_P(this_ptr), "_digest", sizeof("_digest"))) {
6871
unsigned char* buf;
6972
int len;
7073
smart_str auth = {0};
7174

7275
smart_str_appendl(&auth, Z_STRVAL_PP(login), Z_STRLEN_PP(login));
7376
smart_str_appendc(&auth, ':');
74-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password"), (void **)&password) == SUCCESS) {
77+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_password", sizeof("_password"), (void **)&password) == SUCCESS &&
78+
Z_TYPE_PP(password) == IS_STRING) {
7579
smart_str_appendl(&auth, Z_STRVAL_PP(password), Z_STRLEN_PP(password));
7680
}
7781
smart_str_0(&auth);
@@ -571,6 +575,7 @@ int make_http_soap_request(zval *this_ptr,
571575
}
572576
if (!http_1_1 ||
573577
(zend_hash_find(Z_OBJPROP_P(this_ptr), "_keep_alive", sizeof("_keep_alive"), (void **)&tmp) == SUCCESS &&
578+
(Z_TYPE_PP(tmp) == IS_BOOL || Z_TYPE_PP(tmp) == IS_LONG) &&
574579
Z_LVAL_PP(tmp) == 0)) {
575580
smart_str_append_const(&soap_headers, "\r\n"
576581
"Connection: close\r\n");
@@ -804,7 +809,8 @@ int make_http_soap_request(zval *this_ptr,
804809
}
805810

806811
/* Send cookies along with request */
807-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == SUCCESS) {
812+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == SUCCESS &&
813+
Z_TYPE_PP(cookies) == IS_ARRAY) {
808814
zval **data;
809815
char *key;
810816
int i, n;
@@ -847,7 +853,7 @@ int make_http_soap_request(zval *this_ptr,
847853
smart_str_append_const(&soap_headers, "\r\n");
848854
smart_str_0(&soap_headers);
849855
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS &&
850-
Z_LVAL_PP(trace) > 0) {
856+
(Z_TYPE_PP(trace) == IS_BOOL || Z_TYPE_PP(trace) == IS_LONG) && Z_LVAL_PP(trace) != 0) {
851857
add_property_stringl(this_ptr, "__last_request_headers", soap_headers.c, soap_headers.len, 1);
852858
}
853859
smart_str_appendl(&soap_headers, request, request_size);
@@ -892,7 +898,7 @@ int make_http_soap_request(zval *this_ptr,
892898
}
893899

894900
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS &&
895-
Z_LVAL_PP(trace) > 0) {
901+
(Z_TYPE_PP(trace) == IS_BOOL || Z_TYPE_PP(trace) == IS_LONG) && Z_LVAL_PP(trace) != 0) {
896902
add_property_stringl(this_ptr, "__last_response_headers", http_headers, http_header_size, 1);
897903
}
898904

@@ -941,7 +947,8 @@ int make_http_soap_request(zval *this_ptr,
941947
char *eqpos, *sempos;
942948
zval **cookies;
943949

944-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == FAILURE) {
950+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == FAILURE ||
951+
Z_TYPE_PP(cookies) != IS_ARRAY) {
945952
zval *tmp_cookies;
946953
MAKE_STD_ZVAL(tmp_cookies);
947954
array_init(tmp_cookies);

ext/soap/soap.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ static int do_request(zval *this_ptr, xmlDoc *request, char *location, char *act
25642564
}
25652565

25662566
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS &&
2567-
Z_TYPE_PP(trace) == IS_LONG && Z_LVAL_PP(trace) > 0) {
2567+
(Z_LVAL_PP(trace) == IS_BOOL || Z_LVAL_PP(trace) == IS_LONG) && Z_LVAL_PP(trace) != 0) {
25682568
add_property_stringl(this_ptr, "__last_request", buf, buf_size, 1);
25692569
}
25702570

@@ -2599,7 +2599,7 @@ static int do_request(zval *this_ptr, xmlDoc *request, char *location, char *act
25992599
}
26002600
ret = FALSE;
26012601
} else if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS &&
2602-
Z_TYPE_PP(trace) == IS_LONG && Z_LVAL_PP(trace) > 0) {
2602+
(Z_LVAL_PP(trace) == IS_BOOL || Z_LVAL_PP(trace) == IS_LONG) && Z_LVAL_PP(trace) != 0) {
26032603
add_property_stringl(this_ptr, "__last_response", Z_STRVAL_P(response), Z_STRLEN_P(response), 1);
26042604
}
26052605
zval_ptr_dtor(&params[4]);
@@ -2643,13 +2643,13 @@ static void do_soap_call(zval* this_ptr,
26432643

26442644
SOAP_CLIENT_BEGIN_CODE();
26452645

2646-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS
2647-
&& Z_LVAL_PP(trace) > 0) {
2646+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace"), (void **) &trace) == SUCCESS &&
2647+
(Z_LVAL_PP(trace) == IS_BOOL || Z_LVAL_PP(trace) == IS_LONG) && Z_LVAL_PP(trace) != 0) {
26482648
zend_hash_del(Z_OBJPROP_P(this_ptr), "__last_request", sizeof("__last_request"));
26492649
zend_hash_del(Z_OBJPROP_P(this_ptr), "__last_response", sizeof("__last_response"));
26502650
}
2651-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_soap_version", sizeof("_soap_version"), (void **) &tmp) == SUCCESS
2652-
&& Z_LVAL_PP(tmp) == SOAP_1_2) {
2651+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_soap_version", sizeof("_soap_version"), (void **) &tmp) == SUCCESS &&
2652+
Z_TYPE_PP(tmp) == IS_LONG && Z_LVAL_PP(tmp) == SOAP_1_2) {
26532653
soap_version = SOAP_1_2;
26542654
} else {
26552655
soap_version = SOAP_1_1;
@@ -2746,7 +2746,7 @@ static void do_soap_call(zval* this_ptr,
27462746
zval **uri;
27472747
smart_str action = {0};
27482748

2749-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "uri", sizeof("uri"), (void *)&uri) == FAILURE) {
2749+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "uri", sizeof("uri"), (void *)&uri) == FAILURE || Z_TYPE_PP(uri) != IS_STRING) {
27502750
add_soap_fault(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL TSRMLS_CC);
27512751
} else if (location == NULL) {
27522752
add_soap_fault(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL TSRMLS_CC);
@@ -3025,7 +3025,8 @@ PHP_METHOD(SoapClient, __getLastRequest)
30253025
return;
30263026
}
30273027

3028-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_request", sizeof("__last_request"), (void **)&tmp) == SUCCESS) {
3028+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_request", sizeof("__last_request"), (void **)&tmp) == SUCCESS &&
3029+
Z_TYPE_PP(tmp) == IS_STRING) {
30293030
RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1);
30303031
}
30313032
RETURN_NULL();
@@ -3043,7 +3044,8 @@ PHP_METHOD(SoapClient, __getLastResponse)
30433044
return;
30443045
}
30453046

3046-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_response", sizeof("__last_response"), (void **)&tmp) == SUCCESS) {
3047+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_response", sizeof("__last_response"), (void **)&tmp) == SUCCESS &&
3048+
Z_TYPE_PP(tmp) == IS_STRING) {
30473049
RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1);
30483050
}
30493051
RETURN_NULL();
@@ -3061,7 +3063,8 @@ PHP_METHOD(SoapClient, __getLastRequestHeaders)
30613063
return;
30623064
}
30633065

3064-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_request_headers", sizeof("__last_request_headers"), (void **)&tmp) == SUCCESS) {
3066+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_request_headers", sizeof("__last_request_headers"), (void **)&tmp) == SUCCESS &&
3067+
Z_TYPE_PP(tmp) == IS_STRING) {
30653068
RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1);
30663069
}
30673070
RETURN_NULL();
@@ -3079,7 +3082,8 @@ PHP_METHOD(SoapClient, __getLastResponseHeaders)
30793082
return;
30803083
}
30813084

3082-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_response_headers", sizeof("__last_response_headers"), (void **)&tmp) == SUCCESS) {
3085+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__last_response_headers", sizeof("__last_response_headers"), (void **)&tmp) == SUCCESS &&
3086+
Z_TYPE_PP(tmp) == IS_STRING) {
30833087
RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), 1);
30843088
}
30853089
RETURN_NULL();
@@ -3135,13 +3139,15 @@ PHP_METHOD(SoapClient, __setCookie)
31353139
}
31363140

31373141
if (val == NULL) {
3138-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == SUCCESS) {
3142+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == SUCCESS &&
3143+
Z_TYPE_PP(cookies) == IS_ARRAY) {
31393144
zend_hash_del(Z_ARRVAL_PP(cookies), name, name_len+1);
31403145
}
31413146
} else {
31423147
zval *zcookie;
31433148

3144-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == FAILURE) {
3149+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) == FAILURE ||
3150+
Z_TYPE_PP(cookies) != IS_ARRAY) {
31453151
zval *tmp_cookies;
31463152

31473153
MAKE_STD_ZVAL(tmp_cookies);
@@ -3169,7 +3175,8 @@ PHP_METHOD(SoapClient, __getCookies)
31693175

31703176
array_init(return_value);
31713177

3172-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) != FAILURE) {
3178+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies"), (void **)&cookies) != FAILURE &&
3179+
Z_TYPE_PP(cookies) == IS_ARRAY) {
31733180
zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(*cookies), (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*));
31743181
}
31753182
}
@@ -3991,7 +3998,8 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function
39913998
}
39923999

39934000
if (version == SOAP_1_1) {
3994-
if (zend_hash_find(prop, "faultcode", sizeof("faultcode"), (void**)&tmp) == SUCCESS) {
4001+
if (zend_hash_find(prop, "faultcode", sizeof("faultcode"), (void**)&tmp) == SUCCESS &&
4002+
Z_TYPE_PP(tmp) == IS_STRING) {
39954003
size_t new_len;
39964004
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST("faultcode"));
39974005
char *str = php_escape_html_entities((unsigned char*)Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
@@ -4016,7 +4024,8 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function
40164024
}
40174025
detail_name = "detail";
40184026
} else {
4019-
if (zend_hash_find(prop, "faultcode", sizeof("faultcode"), (void**)&tmp) == SUCCESS) {
4027+
if (zend_hash_find(prop, "faultcode", sizeof("faultcode"), (void**)&tmp) == SUCCESS &&
4028+
Z_TYPE_PP(tmp) == IS_STRING) {
40204029
size_t new_len;
40214030
xmlNodePtr node = xmlNewChild(param, ns, BAD_CAST("Code"), NULL);
40224031
char *str = php_escape_html_entities((unsigned char*)Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
@@ -4256,7 +4265,8 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function
42564265
}
42574266
}
42584267
} else {
4259-
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "style", sizeof("style"), (void **)&zstyle) == SUCCESS) {
4268+
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "style", sizeof("style"), (void **)&zstyle) == SUCCESS &&
4269+
Z_TYPE_PP(zstyle) == IS_LONG) {
42604270
style = Z_LVAL_PP(zstyle);
42614271
} else {
42624272
style = SOAP_RPC;
@@ -4279,7 +4289,7 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function
42794289
}
42804290

42814291
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "use", sizeof("use"), (void **)&zuse) == SUCCESS &&
4282-
Z_LVAL_PP(zuse) == SOAP_LITERAL) {
4292+
Z_TYPE_PP(zuse) == IS_LONG && Z_LVAL_PP(zuse) == SOAP_LITERAL) {
42834293
use = SOAP_LITERAL;
42844294
} else {
42854295
use = SOAP_ENCODED;
@@ -4409,6 +4419,7 @@ static xmlNodePtr serialize_parameter(sdlParamPtr param, zval *param_val, int in
44094419
zval **param_data;
44104420

44114421
if (zend_hash_find(Z_OBJPROP_P(param_val), "param_name", sizeof("param_name"), (void **)&param_name) == SUCCESS &&
4422+
Z_TYPE_PP(param_name) == IS_STRING &&
44124423
zend_hash_find(Z_OBJPROP_P(param_val), "param_data", sizeof("param_data"), (void **)&param_data) == SUCCESS) {
44134424
param_val = *param_data;
44144425
name = Z_STRVAL_PP(param_name);

0 commit comments

Comments
 (0)