@@ -166,15 +166,17 @@ static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array,
166
166
}
167
167
} else if (strcmp (ctrl -> ldctl_oid , LDAP_CONTROL_PAGEDRESULTS ) == 0 ) {
168
168
int lestimated , rc ;
169
- struct berval lcookie ;
169
+ struct berval lcookie = { 0 , NULL } ;
170
170
zval value ;
171
171
172
172
if (ctrl -> ldctl_value .bv_len ) {
173
- rc = ldap_parse_pageresponse_control (ld , ctrl , & lestimated , & lcookie );
173
+ /* ldap_parse_pageresponse_control() allocates lcookie.bv_val */
174
+ rc = ldap_parse_pageresponse_control (ld , ctrl , & lestimated , & lcookie ); /* memleak: ??? */
174
175
} else {
175
176
/* ldap_parse_pageresponse_control will crash if value is empty */
176
177
rc = -1 ;
177
178
}
179
+
178
180
if ( rc == LDAP_SUCCESS ) {
179
181
array_init (& value );
180
182
add_assoc_long (& value , "size" , lestimated );
@@ -183,6 +185,10 @@ static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array,
183
185
} else {
184
186
add_assoc_null (array , "value" );
185
187
}
188
+
189
+ if (lcookie .bv_val ) {
190
+ ldap_memfree (lcookie .bv_val );
191
+ }
186
192
} else if ((strcmp (ctrl -> ldctl_oid , LDAP_CONTROL_PRE_READ ) == 0 ) || (strcmp (ctrl -> ldctl_oid , LDAP_CONTROL_POST_READ ) == 0 )) {
187
193
BerElement * ber ;
188
194
struct berval bv ;
@@ -1630,7 +1636,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1630
1636
php_set_opts (ld -> link , ldap_sizelimit , ldap_timelimit , ldap_deref , & old_ldap_sizelimit , & old_ldap_timelimit , & old_ldap_deref );
1631
1637
1632
1638
/* Run the actual search */
1633
- errno = ldap_search_ext_s (ld -> link , ZSTR_VAL (ldap_base_dn ), scope , ZSTR_VAL (ldap_filter ), ldap_attrs , ldap_attrsonly , lserverctrls , NULL , NULL , ldap_sizelimit , & ldap_res );
1639
+ errno = ldap_search_ext_s (ld -> link , ZSTR_VAL (ldap_base_dn ), scope , ZSTR_VAL (ldap_filter ), ldap_attrs , ldap_attrsonly , lserverctrls , NULL , NULL , ldap_sizelimit , & ldap_res ); /* memleak: !!! */
1634
1640
1635
1641
if (errno != LDAP_SUCCESS
1636
1642
&& errno != LDAP_SIZELIMIT_EXCEEDED
@@ -4254,8 +4260,7 @@ PHP_FUNCTION(ldap_exop_passwd)
4254
4260
{
4255
4261
zval * link , * serverctrls ;
4256
4262
struct berval luser , loldpw , lnewpw , lgenpasswd ;
4257
- LDAPControl * * lserverctrls = NULL , * * requestctrls = NULL ;
4258
- LDAPControl * ctrl , * * ctrlp ;
4263
+ LDAPControl * ctrl , * * lserverctrls = NULL , * requestctrls [2 ] = { NULL , NULL };
4259
4264
LDAPMessage * ldap_res ;
4260
4265
ldap_linkdata * ld ;
4261
4266
int rc , myargcount = ZEND_NUM_ARGS (), msgid , err ;
@@ -4275,16 +4280,10 @@ PHP_FUNCTION(ldap_exop_passwd)
4275
4280
4276
4281
switch (myargcount ) {
4277
4282
case 5 :
4278
- requestctrls = safe_emalloc (2 , sizeof (* requestctrls ), 0 );
4279
- * requestctrls = NULL ;
4280
- ctrlp = requestctrls ;
4281
-
4282
- if (ldap_create_passwordpolicy_control (ld -> link , & ctrl ) == LDAP_SUCCESS ) {
4283
- * ctrlp = ctrl ;
4284
- ++ ctrlp ;
4283
+ /* ldap_create_passwordpolicy_control() allocates ctrl */
4284
+ if (ldap_create_passwordpolicy_control (ld -> link , & ctrl ) == LDAP_SUCCESS ) { /* memleak: ??? */
4285
+ requestctrls [0 ] = ctrl ;
4285
4286
}
4286
-
4287
- * ctrlp = NULL ;
4288
4287
}
4289
4288
4290
4289
/* asynchronous call to get result and controls */
@@ -4294,8 +4293,8 @@ PHP_FUNCTION(ldap_exop_passwd)
4294
4293
requestctrls ,
4295
4294
NULL , & msgid );
4296
4295
4297
- if (requestctrls != NULL ) {
4298
- efree (requestctrls );
4296
+ if (requestctrls [ 0 ] != NULL ) {
4297
+ ldap_control_free (requestctrls [ 0 ] );
4299
4298
}
4300
4299
4301
4300
if (rc != LDAP_SUCCESS ) {
@@ -4317,9 +4316,12 @@ PHP_FUNCTION(ldap_exop_passwd)
4317
4316
RETURN_FALSE ;
4318
4317
}
4319
4318
4320
- rc = ldap_parse_result (ld -> link , ldap_res , & err , NULL , & errmsg , NULL , (myargcount > 4 ? & lserverctrls : NULL ), 1 );
4319
+ rc = ldap_parse_result (ld -> link , ldap_res , & err , NULL , & errmsg , NULL , (myargcount > 4 ? & lserverctrls : NULL ), 1 ); /* memleak: ??? */
4321
4320
if ( rc != LDAP_SUCCESS ) {
4322
4321
php_error_docref (NULL , E_WARNING , "Passwd modify extended operation failed: %s (%d)" , ldap_err2string (rc ), rc );
4322
+ if (lserverctrls ) {
4323
+ ldap_controls_free (lserverctrls );
4324
+ }
4323
4325
RETURN_FALSE ;
4324
4326
}
4325
4327
0 commit comments