Skip to content

Commit ec77cca

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
2 parents 646b64b + 98457b6 commit ec77cca

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

ext/ldap/ldap.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array,
278278
static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* array)
279279
{
280280
zval* val;
281-
zend_string *control_oid = NULL;
281+
zend_string *control_oid;
282282
int control_iscritical = 0, rc = LDAP_SUCCESS;
283283
char** ldap_attrs = NULL;
284284
LDAPSortKey** sort_keys = NULL;
@@ -311,7 +311,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
311311
} else {
312312
tmpstring = zval_get_string(val);
313313
if (EG(exception)) {
314-
return -1;
314+
rc = -1;
315+
goto failure;
315316
}
316317
control_value->bv_val = ZSTR_VAL(tmpstring);
317318
control_value->bv_len = ZSTR_LEN(tmpstring);
@@ -368,6 +369,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
368369
php_error_docref(NULL, E_WARNING, "Failed to create assert control value: %s (%d)", ldap_err2string(rc), rc);
369370
}
370371
}
372+
zend_string_release(assert);
371373
}
372374
} else if (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_VALUESRETURNFILTER) == 0) {
373375
zval* tmp;
@@ -584,6 +586,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
584586
}
585587

586588
failure:
589+
zend_string_release(control_oid);
590+
if (tmpstring != NULL) {
591+
zend_string_release(tmpstring);
592+
}
587593
if (control_value != NULL) {
588594
ber_memfree(control_value);
589595
control_value = NULL;
@@ -1462,7 +1468,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14621468
{
14631469
zval *link, *base_dn, *filter, *attrs = NULL, *attr, *serverctrls = NULL;
14641470
zend_long attrsonly, sizelimit, timelimit, deref;
1465-
zend_string *ldap_filter = NULL, *ldap_base_dn = NULL, *tmpstring;
1471+
zend_string *ldap_filter = NULL, *ldap_base_dn = NULL;
14661472
char **ldap_attrs = NULL;
14671473
ldap_linkdata *ld = NULL;
14681474
LDAPMessage *ldap_res;
@@ -1471,7 +1477,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14711477
int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1;
14721478
int num_attribs = 0, ret = 1, i, errno, argcount = ZEND_NUM_ARGS();
14731479

1474-
if (zend_parse_parameters(argcount, "zzz|alllla", &link, &base_dn, &filter, &attrs, &attrsonly,
1480+
if (zend_parse_parameters(argcount, "zzz|alllla/", &link, &base_dn, &filter, &attrs, &attrsonly,
14751481
&sizelimit, &timelimit, &deref, &serverctrls) == FAILURE) {
14761482
return;
14771483
}
@@ -1498,12 +1504,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14981504
goto cleanup;
14991505
}
15001506

1501-
tmpstring = zval_get_string(attr);
1507+
convert_to_string(attr);
15021508
if (EG(exception)) {
15031509
ret = 0;
15041510
goto cleanup;
15051511
}
1506-
ldap_attrs[i] = ZSTR_VAL(tmpstring);
1512+
ldap_attrs[i] = Z_STRVAL_P(attr);
15071513
}
15081514
ldap_attrs[num_attribs] = NULL;
15091515
default:
@@ -1686,6 +1692,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16861692
/* Restoring previous options */
16871693
php_set_opts(ld->link, old_ldap_sizelimit, old_ldap_timelimit, old_ldap_deref, &ldap_sizelimit, &ldap_timelimit, &ldap_deref);
16881694
}
1695+
if (ldap_filter) {
1696+
zend_string_release(ldap_filter);
1697+
}
1698+
if (ldap_base_dn) {
1699+
zend_string_release(ldap_base_dn);
1700+
}
16891701
if (ldap_attrs != NULL) {
16901702
efree(ldap_attrs);
16911703
}
@@ -2219,7 +2231,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22192231
int i, j, num_attribs, num_values, msgid;
22202232
size_t dn_len;
22212233
int *num_berval;
2222-
zend_string *attribute, *tmpstring;
2234+
zend_string *attribute;
22232235
zend_ulong index;
22242236
int is_full_add=0; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
22252237

@@ -2280,14 +2292,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22802292

22812293
/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
22822294
if ((num_values == 1) && (Z_TYPE_P(value) != IS_ARRAY)) {
2283-
tmpstring = zval_get_string(value);
2295+
convert_to_string(value);
22842296
if (EG(exception)) {
22852297
RETVAL_FALSE;
22862298
goto cleanup;
22872299
}
22882300
ldap_mods[i]->mod_bvalues[0] = (struct berval *) emalloc (sizeof(struct berval));
2289-
ldap_mods[i]->mod_bvalues[0]->bv_val = ZSTR_VAL(tmpstring);
2290-
ldap_mods[i]->mod_bvalues[0]->bv_len = ZSTR_LEN(tmpstring);
2301+
ldap_mods[i]->mod_bvalues[0]->bv_val = Z_STRVAL_P(value);
2302+
ldap_mods[i]->mod_bvalues[0]->bv_len = Z_STRLEN_P(value);
22912303
} else {
22922304
for (j = 0; j < num_values; j++) {
22932305
if ((ivalue = zend_hash_index_find(Z_ARRVAL_P(value), j)) == NULL) {
@@ -2297,14 +2309,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
22972309
RETVAL_FALSE;
22982310
goto cleanup;
22992311
}
2300-
tmpstring = zval_get_string(ivalue);
2312+
convert_to_string(ivalue);
23012313
if (EG(exception)) {
23022314
RETVAL_FALSE;
23032315
goto cleanup;
23042316
}
23052317
ldap_mods[i]->mod_bvalues[j] = (struct berval *) emalloc (sizeof(struct berval));
2306-
ldap_mods[i]->mod_bvalues[j]->bv_val = ZSTR_VAL(tmpstring);
2307-
ldap_mods[i]->mod_bvalues[j]->bv_len = ZSTR_LEN(tmpstring);
2318+
ldap_mods[i]->mod_bvalues[j]->bv_val = Z_STRVAL_P(ivalue);
2319+
ldap_mods[i]->mod_bvalues[j]->bv_len = Z_STRLEN_P(ivalue);
23082320
}
23092321
}
23102322
ldap_mods[i]->mod_bvalues[num_values] = NULL;
@@ -2829,6 +2841,7 @@ PHP_FUNCTION(ldap_modify_batch)
28292841
/* fill it */
28302842
ldap_mods[i]->mod_bvalues[j]->bv_len = ZSTR_LEN(modval);
28312843
ldap_mods[i]->mod_bvalues[j]->bv_val = estrndup(ZSTR_VAL(modval), ZSTR_LEN(modval));
2844+
zend_string_release(modval);
28322845
}
28332846

28342847
/* NULL-terminate values */
@@ -3332,8 +3345,10 @@ PHP_FUNCTION(ldap_set_option)
33323345
RETURN_FALSE;
33333346
}
33343347
if (ldap_set_option(ldap, option, ZSTR_VAL(val))) {
3348+
zend_string_release(val);
33353349
RETURN_FALSE;
33363350
}
3351+
zend_string_release(val);
33373352
} break;
33383353
/* options with boolean value */
33393354
case LDAP_OPT_REFERRALS:

0 commit comments

Comments
 (0)