@@ -279,7 +279,7 @@ static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array,
279
279
static int _php_ldap_control_from_array (LDAP * ld , LDAPControl * * ctrl , zval * array )
280
280
{
281
281
zval * val ;
282
- zend_string * control_oid = NULL ;
282
+ zend_string * control_oid ;
283
283
int control_iscritical = 0 , rc = LDAP_SUCCESS ;
284
284
char * * ldap_attrs = NULL ;
285
285
LDAPSortKey * * sort_keys = NULL ;
@@ -312,7 +312,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
312
312
} else {
313
313
tmpstring = zval_get_string (val );
314
314
if (EG (exception )) {
315
- return -1 ;
315
+ rc = -1 ;
316
+ goto failure ;
316
317
}
317
318
control_value -> bv_val = ZSTR_VAL (tmpstring );
318
319
control_value -> bv_len = ZSTR_LEN (tmpstring );
@@ -369,6 +370,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
369
370
php_error_docref (NULL , E_WARNING , "Failed to create assert control value: %s (%d)" , ldap_err2string (rc ), rc );
370
371
}
371
372
}
373
+ zend_string_release (assert );
372
374
}
373
375
} else if (strcmp (ZSTR_VAL (control_oid ), LDAP_CONTROL_VALUESRETURNFILTER ) == 0 ) {
374
376
zval * tmp ;
@@ -585,6 +587,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
585
587
}
586
588
587
589
failure :
590
+ zend_string_release (control_oid );
591
+ if (tmpstring != NULL ) {
592
+ zend_string_release (tmpstring );
593
+ }
588
594
if (control_value != NULL ) {
589
595
ber_memfree (control_value );
590
596
control_value = NULL ;
@@ -1456,7 +1462,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1456
1462
{
1457
1463
zval * link , * base_dn , * filter , * attrs = NULL , * attr , * serverctrls = NULL ;
1458
1464
zend_long attrsonly , sizelimit , timelimit , deref ;
1459
- zend_string * ldap_filter = NULL , * ldap_base_dn = NULL , * tmpstring ;
1465
+ zend_string * ldap_filter = NULL , * ldap_base_dn = NULL ;
1460
1466
char * * ldap_attrs = NULL ;
1461
1467
ldap_linkdata * ld = NULL ;
1462
1468
LDAPMessage * ldap_res ;
@@ -1465,7 +1471,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1465
1471
int old_ldap_sizelimit = -1 , old_ldap_timelimit = -1 , old_ldap_deref = -1 ;
1466
1472
int num_attribs = 0 , ret = 1 , i , errno , argcount = ZEND_NUM_ARGS ();
1467
1473
1468
- if (zend_parse_parameters (argcount , "zzz|alllla" , & link , & base_dn , & filter , & attrs , & attrsonly ,
1474
+ if (zend_parse_parameters (argcount , "zzz|alllla/ " , & link , & base_dn , & filter , & attrs , & attrsonly ,
1469
1475
& sizelimit , & timelimit , & deref , & serverctrls ) == FAILURE ) {
1470
1476
return ;
1471
1477
}
@@ -1492,12 +1498,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1492
1498
goto cleanup ;
1493
1499
}
1494
1500
1495
- tmpstring = zval_get_string (attr );
1501
+ convert_to_string (attr );
1496
1502
if (EG (exception )) {
1497
1503
ret = 0 ;
1498
1504
goto cleanup ;
1499
1505
}
1500
- ldap_attrs [i ] = ZSTR_VAL ( tmpstring );
1506
+ ldap_attrs [i ] = Z_STRVAL_P ( attr );
1501
1507
}
1502
1508
ldap_attrs [num_attribs ] = NULL ;
1503
1509
default :
@@ -1680,6 +1686,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1680
1686
/* Restoring previous options */
1681
1687
php_set_opts (ld -> link , old_ldap_sizelimit , old_ldap_timelimit , old_ldap_deref , & ldap_sizelimit , & ldap_timelimit , & ldap_deref );
1682
1688
}
1689
+ if (ldap_filter ) {
1690
+ zend_string_release (ldap_filter );
1691
+ }
1692
+ if (ldap_base_dn ) {
1693
+ zend_string_release (ldap_base_dn );
1694
+ }
1683
1695
if (ldap_attrs != NULL ) {
1684
1696
efree (ldap_attrs );
1685
1697
}
@@ -2213,7 +2225,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2213
2225
int i , j , num_attribs , num_values , msgid ;
2214
2226
size_t dn_len ;
2215
2227
int * num_berval ;
2216
- zend_string * attribute , * tmpstring ;
2228
+ zend_string * attribute ;
2217
2229
zend_ulong index ;
2218
2230
int is_full_add = 0 ; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
2219
2231
@@ -2274,14 +2286,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2274
2286
2275
2287
/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
2276
2288
if ((num_values == 1 ) && (Z_TYPE_P (value ) != IS_ARRAY )) {
2277
- tmpstring = zval_get_string (value );
2289
+ convert_to_string (value );
2278
2290
if (EG (exception )) {
2279
2291
RETVAL_FALSE ;
2280
2292
goto cleanup ;
2281
2293
}
2282
2294
ldap_mods [i ]-> mod_bvalues [0 ] = (struct berval * ) emalloc (sizeof (struct berval ));
2283
- ldap_mods [i ]-> mod_bvalues [0 ]-> bv_val = ZSTR_VAL ( tmpstring );
2284
- ldap_mods [i ]-> mod_bvalues [0 ]-> bv_len = ZSTR_LEN ( tmpstring );
2295
+ ldap_mods [i ]-> mod_bvalues [0 ]-> bv_val = Z_STRVAL_P ( value );
2296
+ ldap_mods [i ]-> mod_bvalues [0 ]-> bv_len = Z_STRLEN_P ( value );
2285
2297
} else {
2286
2298
for (j = 0 ; j < num_values ; j ++ ) {
2287
2299
if ((ivalue = zend_hash_index_find (Z_ARRVAL_P (value ), j )) == NULL ) {
@@ -2291,14 +2303,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2291
2303
RETVAL_FALSE ;
2292
2304
goto cleanup ;
2293
2305
}
2294
- tmpstring = zval_get_string (ivalue );
2306
+ convert_to_string (ivalue );
2295
2307
if (EG (exception )) {
2296
2308
RETVAL_FALSE ;
2297
2309
goto cleanup ;
2298
2310
}
2299
2311
ldap_mods [i ]-> mod_bvalues [j ] = (struct berval * ) emalloc (sizeof (struct berval ));
2300
- ldap_mods [i ]-> mod_bvalues [j ]-> bv_val = ZSTR_VAL ( tmpstring );
2301
- ldap_mods [i ]-> mod_bvalues [j ]-> bv_len = ZSTR_LEN ( tmpstring );
2312
+ ldap_mods [i ]-> mod_bvalues [j ]-> bv_val = Z_STRVAL_P ( ivalue );
2313
+ ldap_mods [i ]-> mod_bvalues [j ]-> bv_len = Z_STRLEN_P ( ivalue );
2302
2314
}
2303
2315
}
2304
2316
ldap_mods [i ]-> mod_bvalues [num_values ] = NULL ;
@@ -2823,6 +2835,7 @@ PHP_FUNCTION(ldap_modify_batch)
2823
2835
/* fill it */
2824
2836
ldap_mods [i ]-> mod_bvalues [j ]-> bv_len = ZSTR_LEN (modval );
2825
2837
ldap_mods [i ]-> mod_bvalues [j ]-> bv_val = estrndup (ZSTR_VAL (modval ), ZSTR_LEN (modval ));
2838
+ zend_string_release (modval );
2826
2839
}
2827
2840
2828
2841
/* NULL-terminate values */
@@ -3187,6 +3200,7 @@ PHP_FUNCTION(ldap_get_option)
3187
3200
}
3188
3201
RETURN_FALSE ;
3189
3202
}
3203
+ zval_ptr_dtor (retval );
3190
3204
_php_ldap_controls_to_array (ld -> link , ctrls , retval , 1 );
3191
3205
} break ;
3192
3206
/* options not implemented
@@ -3331,8 +3345,10 @@ PHP_FUNCTION(ldap_set_option)
3331
3345
RETURN_FALSE ;
3332
3346
}
3333
3347
if (ldap_set_option (ldap , option , ZSTR_VAL (val ))) {
3348
+ zend_string_release (val );
3334
3349
RETURN_FALSE ;
3335
3350
}
3351
+ zend_string_release (val );
3336
3352
} break ;
3337
3353
/* options with boolean value */
3338
3354
case LDAP_OPT_REFERRALS :
0 commit comments