Skip to content

Commit 4b2cc62

Browse files
committed
More fixes for bug #73089
Insert a lot more DEREFs. Some may not be necessary, but better safe than sorry. I'm thinking the soap_hash_str_find_deref function should become part of the zend_hash API -- we need this in many places.
1 parent 13fc1b9 commit 4b2cc62

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

ext/soap/php_encoding.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ static encodePtr find_encoder_by_type_name(sdlPtr sdl, const char *type)
283283
return NULL;
284284
}
285285

286+
static zval *soap_hash_str_find_deref(HashTable *ht, const char *str, size_t len) {
287+
zval *zv = zend_hash_str_find(ht, str, len);
288+
if (!zv) {
289+
return NULL;
290+
}
291+
292+
ZVAL_DEREF(zv);
293+
return zv;
294+
}
295+
286296
static zend_bool soap_check_zval_ref(zval *data, xmlNodePtr node) {
287297
xmlNodePtr node_ptr;
288298

@@ -380,6 +390,10 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
380390
xmlNodePtr node = NULL;
381391
int add_type = 0;
382392

393+
if (data) {
394+
ZVAL_DEREF(data);
395+
}
396+
383397
/* Special handling of class SoapVar */
384398
if (data &&
385399
Z_TYPE_P(data) == IS_OBJECT &&
@@ -388,14 +402,14 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
388402
encodePtr enc = NULL;
389403
HashTable *ht = Z_OBJPROP_P(data);
390404

391-
if ((ztype = zend_hash_str_find(ht, "enc_type", sizeof("enc_type")-1)) == NULL ||
405+
if ((ztype = soap_hash_str_find_deref(ht, "enc_type", sizeof("enc_type")-1)) == NULL ||
392406
Z_TYPE_P(ztype) != IS_LONG) {
393407
soap_error0(E_ERROR, "Encoding: SoapVar has no 'enc_type' property");
394408
}
395409

396-
if ((zstype = zend_hash_str_find(ht, "enc_stype", sizeof("enc_stype")-1)) != NULL &&
410+
if ((zstype = soap_hash_str_find_deref(ht, "enc_stype", sizeof("enc_stype")-1)) != NULL &&
397411
Z_TYPE_P(zstype) == IS_STRING) {
398-
if ((zns = zend_hash_str_find(ht, "enc_ns", sizeof("enc_ns")-1)) != NULL &&
412+
if ((zns = soap_hash_str_find_deref(ht, "enc_ns", sizeof("enc_ns")-1)) != NULL &&
399413
Z_TYPE_P(zns) == IS_STRING) {
400414
enc = get_encoder(SOAP_GLOBAL(sdl), Z_STRVAL_P(zns), Z_STRVAL_P(zstype));
401415
} else {
@@ -422,13 +436,13 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
422436
enc = encode;
423437
}
424438

425-
zdata = zend_hash_str_find(ht, "enc_value", sizeof("enc_value")-1);
439+
zdata = soap_hash_str_find_deref(ht, "enc_value", sizeof("enc_value")-1);
426440
node = master_to_xml(enc, zdata, style, parent);
427441

428442
if (style == SOAP_ENCODED || (SOAP_GLOBAL(sdl) && encode != enc)) {
429-
if ((zstype = zend_hash_str_find(ht, "enc_stype", sizeof("enc_stype")-1)) != NULL &&
443+
if ((zstype = soap_hash_str_find_deref(ht, "enc_stype", sizeof("enc_stype")-1)) != NULL &&
430444
Z_TYPE_P(zstype) == IS_STRING) {
431-
if ((zns = zend_hash_str_find(ht, "enc_ns", sizeof("enc_ns")-1)) != NULL &&
445+
if ((zns = soap_hash_str_find_deref(ht, "enc_ns", sizeof("enc_ns")-1)) != NULL &&
432446
Z_TYPE_P(zns) == IS_STRING) {
433447
set_ns_and_type_ex(node, Z_STRVAL_P(zns), Z_STRVAL_P(zstype));
434448
} else {
@@ -437,11 +451,11 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
437451
}
438452
}
439453

440-
if ((zname = zend_hash_str_find(ht, "enc_name", sizeof("enc_name")-1)) != NULL &&
454+
if ((zname = soap_hash_str_find_deref(ht, "enc_name", sizeof("enc_name")-1)) != NULL &&
441455
Z_TYPE_P(zname) == IS_STRING) {
442456
xmlNodeSetName(node, BAD_CAST(Z_STRVAL_P(zname)));
443457
}
444-
if ((znamens = zend_hash_str_find(ht, "enc_namens", sizeof("enc_namens")-1)) != NULL &&
458+
if ((znamens = soap_hash_str_find_deref(ht, "enc_namens", sizeof("enc_namens")-1)) != NULL &&
445459
Z_TYPE_P(znamens) == IS_STRING) {
446460
xmlNsPtr nsp = encode_add_ns(node, Z_STRVAL_P(znamens));
447461
xmlSetNs(node, nsp);
@@ -455,6 +469,7 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml
455469
zend_string *type_name;
456470

457471
ZEND_HASH_FOREACH_STR_KEY_VAL(SOAP_GLOBAL(class_map), type_name, tmp) {
472+
ZVAL_DEREF(tmp);
458473
if (Z_TYPE_P(tmp) == IS_STRING &&
459474
ZSTR_LEN(ce->name) == Z_STRLEN_P(tmp) &&
460475
zend_binary_strncasecmp(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), Z_STRVAL_P(tmp), ZSTR_LEN(ce->name), ZSTR_LEN(ce->name)) == 0 &&
@@ -1193,20 +1208,18 @@ static zval* get_zval_property(zval* object, char* name, zval *rv)
11931208
if (property_info != ZEND_WRONG_PROPERTY_INFO && property_info &&
11941209
zend_hash_exists(Z_OBJPROP_P(object), property_info->name)) {
11951210
zval_ptr_dtor(&member);
1211+
ZVAL_DEREF(data);
11961212
return data;
11971213
}
11981214
zval_ptr_dtor(&member);
11991215
return NULL;
12001216
}
12011217
zval_ptr_dtor(&member);
12021218
EG(scope) = old_scope;
1219+
ZVAL_DEREF(data);
12031220
return data;
12041221
} else if (Z_TYPE_P(object) == IS_ARRAY) {
1205-
zval *data_ptr;
1206-
1207-
if ((data_ptr = zend_hash_str_find(Z_ARRVAL_P(object), name, strlen(name))) != NULL) {
1208-
return data_ptr;
1209-
}
1222+
return soap_hash_str_find_deref(Z_ARRVAL_P(object), name, strlen(name));
12101223
}
12111224
return NULL;
12121225
}
@@ -1421,7 +1434,7 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
14211434
zval *classname;
14221435
zend_class_entry *tmp;
14231436

1424-
if ((classname = zend_hash_str_find(SOAP_GLOBAL(class_map), type->type_str, strlen(type->type_str))) != NULL &&
1437+
if ((classname = soap_hash_str_find_deref(SOAP_GLOBAL(class_map), type->type_str, strlen(type->type_str))) != NULL &&
14251438
Z_TYPE_P(classname) == IS_STRING &&
14261439
(tmp = zend_fetch_class(Z_STR_P(classname), ZEND_FETCH_CLASS_AUTO)) != NULL) {
14271440
ce = tmp;
@@ -1642,6 +1655,7 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval *
16421655
zval *val;
16431656

16441657
ZEND_HASH_FOREACH_VAL(ht, val) {
1658+
ZVAL_DEREF(val);
16451659
if (Z_TYPE_P(val) == IS_NULL && model->u.element->nillable) {
16461660
property = xmlNewNode(NULL, BAD_CAST("BOGUS"));
16471661
xmlAddChild(node, property);
@@ -1896,6 +1910,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo
18961910

18971911
ZEND_HASH_FOREACH_VAL(prop, val) {
18981912
xmlNodePtr property;
1913+
ZVAL_DEREF(val);
18991914
if (Z_TYPE_P(val) == IS_NULL && array_el->nillable) {
19001915
property = xmlNewNode(NULL, BAD_CAST("BOGUS"));
19011916
xmlAddChild(xmlParam, property);
@@ -2327,6 +2342,7 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
23272342
ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(el), el) {
23282343
break;
23292344
} ZEND_HASH_FOREACH_END();
2345+
ZVAL_DEREF(el);
23302346
if (Z_TYPE_P(el) == IS_ARRAY) {
23312347
dims[i] = zend_hash_num_elements(Z_ARRVAL_P(el));
23322348
} else {
@@ -3520,20 +3536,20 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type)
35203536
Z_OBJCE_P(tmp) == soap_var_class_entry) {
35213537
zval *ztype;
35223538

3523-
if ((ztype = zend_hash_str_find(Z_OBJPROP_P(tmp), "enc_type", sizeof("enc_type")-1)) == NULL ||
3539+
if ((ztype = soap_hash_str_find_deref(Z_OBJPROP_P(tmp), "enc_type", sizeof("enc_type")-1)) == NULL ||
35243540
Z_TYPE_P(ztype) != IS_LONG) {
35253541
soap_error0(E_ERROR, "Encoding: SoapVar has no 'enc_type' property");
35263542
}
35273543
cur_type = Z_LVAL_P(ztype);
35283544

3529-
if ((ztype = zend_hash_str_find(Z_OBJPROP_P(tmp), "enc_stype", sizeof("enc_stype")-1)) != NULL &&
3545+
if ((ztype = soap_hash_str_find_deref(Z_OBJPROP_P(tmp), "enc_stype", sizeof("enc_stype")-1)) != NULL &&
35303546
Z_TYPE_P(ztype) == IS_STRING) {
35313547
cur_stype = Z_STRVAL_P(ztype);
35323548
} else {
35333549
cur_stype = NULL;
35343550
}
35353551

3536-
if ((ztype = zend_hash_str_find(Z_OBJPROP_P(tmp), "enc_ns", sizeof("enc_ns")-1)) != NULL &&
3552+
if ((ztype = soap_hash_str_find_deref(Z_OBJPROP_P(tmp), "enc_ns", sizeof("enc_ns")-1)) != NULL &&
35373553
Z_TYPE_P(ztype) == IS_STRING) {
35383554
cur_ns = Z_STRVAL_P(ztype);
35393555
} else {

0 commit comments

Comments
 (0)