@@ -1486,12 +1486,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1486
1486
1487
1487
/* parallel search? */
1488
1488
if (Z_TYPE_P (link ) == IS_ARRAY ) {
1489
- int i , nlinks , nbases , nfilters , * rcs ;
1489
+ int i , * rcs ;
1490
1490
ldap_linkdata * * lds ;
1491
1491
zval * entry , object ;
1492
1492
1493
- nlinks = zend_hash_num_elements (Z_ARRVAL_P (link ));
1494
- if (nlinks == 0 ) {
1493
+ uint32_t num_links = zend_hash_num_elements (Z_ARRVAL_P (link ));
1494
+ if (num_links == 0 ) {
1495
1495
zend_argument_must_not_be_empty_error (1 );
1496
1496
ret = 0 ;
1497
1497
goto cleanup ;
@@ -1502,43 +1502,57 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1502
1502
goto cleanup ;
1503
1503
}
1504
1504
1505
+ uint32_t num_base_dns = 0 ; /* If 0 this means we are working with a unique base dn */
1505
1506
if (base_dn_ht ) {
1506
- nbases = zend_hash_num_elements (base_dn_ht );
1507
- if (nbases != nlinks ) {
1508
- zend_argument_value_error (2 , "must have the same number of elements as the links array" );
1507
+ if (!zend_array_is_list (base_dn_ht )) {
1508
+ zend_argument_value_error (2 , "must be a list" );
1509
+ ret = 0 ;
1510
+ goto cleanup ;
1511
+ }
1512
+ num_base_dns = zend_hash_num_elements (base_dn_ht );
1513
+ if (num_base_dns != num_links ) {
1514
+ zend_argument_value_error (2 , "must be the same size as argument #1" );
1509
1515
ret = 0 ;
1510
1516
goto cleanup ;
1511
1517
}
1512
1518
zend_hash_internal_pointer_reset (base_dn_ht );
1513
1519
} else {
1514
- nbases = 0 ; /* this means string, not array */
1515
- ldap_base_dn = zend_string_copy (base_dn_str );
1516
- if (EG (exception )) {
1520
+ if (zend_str_has_nul_byte (base_dn_str )) {
1521
+ zend_argument_value_error (2 , "must not contain null bytes" );
1517
1522
ret = 0 ;
1518
1523
goto cleanup ;
1519
1524
}
1520
- // TODO check filter does not have any nul bytes
1525
+ ldap_base_dn = zend_string_copy ( base_dn_str );
1521
1526
}
1522
1527
1528
+ uint32_t num_filters = 0 ; /* If 0 this means we are working with a unique base dn */
1523
1529
if (filter_ht ) {
1524
- nfilters = zend_hash_num_elements (filter_ht );
1525
- if (nfilters != nlinks ) {
1526
- zend_argument_value_error (3 , "must have the same number of elements as the links array" );
1530
+ if (!zend_array_is_list (filter_ht )) {
1531
+ zend_argument_value_error (3 , "must be a list" );
1532
+ ret = 0 ;
1533
+ goto cleanup ;
1534
+ }
1535
+ num_filters = zend_hash_num_elements (filter_ht );
1536
+ if (num_filters != num_links ) {
1537
+ zend_argument_value_error (3 , "must be the same size as argument #1" );
1527
1538
ret = 0 ;
1528
1539
goto cleanup ;
1529
1540
}
1530
1541
zend_hash_internal_pointer_reset (filter_ht );
1531
1542
} else {
1532
- nfilters = 0 ; /* this means string, not array */
1543
+ if (zend_str_has_nul_byte (filter_str )) {
1544
+ zend_argument_value_error (3 , "must not contain null bytes" );
1545
+ ret = 0 ;
1546
+ goto cleanup ;
1547
+ }
1533
1548
ldap_filter = zend_string_copy (filter_str );
1534
- // TODO check filter does not have any nul bytes
1535
1549
}
1536
1550
1537
- lds = safe_emalloc (nlinks , sizeof (ldap_linkdata ), 0 );
1538
- rcs = safe_emalloc (nlinks , sizeof (* rcs ), 0 );
1551
+ lds = safe_emalloc (num_links , sizeof (ldap_linkdata ), 0 );
1552
+ rcs = safe_emalloc (num_links , sizeof (* rcs ), 0 );
1539
1553
1540
1554
zend_hash_internal_pointer_reset (Z_ARRVAL_P (link ));
1541
- for (i = 0 ; i < nlinks ; i ++ ) {
1555
+ for (i = 0 ; i < num_links ; i ++ ) {
1542
1556
entry = zend_hash_get_current_data (Z_ARRVAL_P (link ));
1543
1557
1544
1558
if (Z_TYPE_P (entry ) != IS_OBJECT || !instanceof_function (Z_OBJCE_P (entry ), ldap_link_ce )) {
@@ -1554,7 +1568,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1554
1568
goto cleanup_parallel ;
1555
1569
}
1556
1570
1557
- if (nbases != 0 ) { /* base_dn an array? */
1571
+ if (num_base_dns != 0 ) { /* base_dn an array? */
1558
1572
entry = zend_hash_get_current_data (base_dn_ht );
1559
1573
zend_hash_move_forward (base_dn_ht );
1560
1574
ldap_base_dn = zval_get_string (entry );
@@ -1564,7 +1578,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1564
1578
}
1565
1579
// TODO check dn does not have any nul bytes
1566
1580
}
1567
- if (nfilters != 0 ) { /* filter an array? */
1581
+ if (num_filters != 0 ) { /* filter an array? */
1568
1582
entry = zend_hash_get_current_data (filter_ht );
1569
1583
zend_hash_move_forward (filter_ht );
1570
1584
ldap_filter = zval_get_string (entry );
@@ -1596,7 +1610,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1596
1610
array_init (return_value );
1597
1611
1598
1612
/* Collect results from the searches */
1599
- for (i = 0 ; i < nlinks ; i ++ ) {
1613
+ for (i = 0 ; i < num_links ; i ++ ) {
1600
1614
if (rcs [i ] != -1 ) {
1601
1615
rcs [i ] = ldap_result (lds [i ]-> link , LDAP_RES_ANY , 1 /* LDAP_MSG_ALL */ , NULL , & ldap_res );
1602
1616
}
0 commit comments