@@ -1485,54 +1485,66 @@ 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 ;
1497
1497
}
1498
1498
1499
+ uint32_t num_base_dns = 0 ; /* If 0 this means we are working with a unique base dn */
1499
1500
if (base_dn_ht ) {
1500
- nbases = zend_hash_num_elements (base_dn_ht );
1501
- if (nbases != nlinks ) {
1502
- zend_argument_value_error (2 , "must have the same number of elements as the links array" );
1501
+ if (!zend_array_is_list (base_dn_ht )) {
1502
+ zend_argument_value_error (2 , "must be a list" );
1503
+ RETURN_THROWS ();
1504
+ }
1505
+ num_base_dns = zend_hash_num_elements (base_dn_ht );
1506
+ if (num_base_dns != num_links ) {
1507
+ zend_argument_value_error (2 , "must be the same size as argument #1" );
1503
1508
ret = 0 ;
1504
1509
goto cleanup ;
1505
1510
}
1506
1511
zend_hash_internal_pointer_reset (base_dn_ht );
1507
1512
} else {
1508
- nbases = 0 ; /* this means string, not array */
1509
- ldap_base_dn = zend_string_copy (base_dn_str );
1510
- if (EG (exception )) {
1513
+ if (zend_str_has_nul_byte (base_dn_str )) {
1514
+ zend_argument_value_error (2 , "must not contain null bytes" );
1511
1515
ret = 0 ;
1512
1516
goto cleanup ;
1513
1517
}
1514
- // TODO check filter does not have any nul bytes
1518
+ ldap_base_dn = zend_string_copy ( base_dn_str );
1515
1519
}
1516
1520
1521
+ uint32_t num_filters = 0 ; /* If 0 this means we are working with a unique base dn */
1517
1522
if (filter_ht ) {
1518
- nfilters = zend_hash_num_elements (filter_ht );
1519
- if (nfilters != nlinks ) {
1520
- zend_argument_value_error (3 , "must have the same number of elements as the links array" );
1523
+ if (!zend_array_is_list (filter_ht )) {
1524
+ zend_argument_value_error (3 , "must be a list" );
1525
+ RETURN_THROWS ();
1526
+ }
1527
+ num_filters = zend_hash_num_elements (filter_ht );
1528
+ if (num_filters != num_links ) {
1529
+ zend_argument_value_error (3 , "must be the same size as argument #1" );
1521
1530
ret = 0 ;
1522
1531
goto cleanup ;
1523
1532
}
1524
1533
zend_hash_internal_pointer_reset (filter_ht );
1525
1534
} else {
1526
- nfilters = 0 ; /* this means string, not array */
1535
+ if (zend_str_has_nul_byte (filter_str )) {
1536
+ zend_argument_value_error (3 , "must not contain null bytes" );
1537
+ ret = 0 ;
1538
+ goto cleanup ;
1539
+ }
1527
1540
ldap_filter = zend_string_copy (filter_str );
1528
- // TODO check filter does not have any nul bytes
1529
1541
}
1530
1542
1531
- lds = safe_emalloc (nlinks , sizeof (ldap_linkdata ), 0 );
1532
- rcs = safe_emalloc (nlinks , sizeof (* rcs ), 0 );
1543
+ lds = safe_emalloc (num_links , sizeof (ldap_linkdata ), 0 );
1544
+ rcs = safe_emalloc (num_links , sizeof (* rcs ), 0 );
1533
1545
1534
1546
zend_hash_internal_pointer_reset (Z_ARRVAL_P (link ));
1535
- for (i = 0 ; i < nlinks ; i ++ ) {
1547
+ for (i = 0 ; i < num_links ; i ++ ) {
1536
1548
entry = zend_hash_get_current_data (Z_ARRVAL_P (link ));
1537
1549
1538
1550
if (Z_TYPE_P (entry ) != IS_OBJECT || !instanceof_function (Z_OBJCE_P (entry ), ldap_link_ce )) {
@@ -1548,7 +1560,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1548
1560
goto cleanup_parallel ;
1549
1561
}
1550
1562
1551
- if (nbases != 0 ) { /* base_dn an array? */
1563
+ if (num_base_dns != 0 ) { /* base_dn an array? */
1552
1564
entry = zend_hash_get_current_data (base_dn_ht );
1553
1565
zend_hash_move_forward (base_dn_ht );
1554
1566
ldap_base_dn = zval_get_string (entry );
@@ -1558,7 +1570,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1558
1570
}
1559
1571
// TODO check dn does not have any nul bytes
1560
1572
}
1561
- if (nfilters != 0 ) { /* filter an array? */
1573
+ if (num_filters != 0 ) { /* filter an array? */
1562
1574
entry = zend_hash_get_current_data (filter_ht );
1563
1575
zend_hash_move_forward (filter_ht );
1564
1576
ldap_filter = zval_get_string (entry );
@@ -1590,7 +1602,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1590
1602
array_init (return_value );
1591
1603
1592
1604
/* Collect results from the searches */
1593
- for (i = 0 ; i < nlinks ; i ++ ) {
1605
+ for (i = 0 ; i < num_links ; i ++ ) {
1594
1606
if (rcs [i ] != -1 ) {
1595
1607
rcs [i ] = ldap_result (lds [i ]-> link , LDAP_RES_ANY , 1 /* LDAP_MSG_ALL */ , NULL , & ldap_res );
1596
1608
}
0 commit comments