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