@@ -451,7 +451,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
451
451
bool control_value_alloc = false;
452
452
int rc = LDAP_SUCCESS ;
453
453
454
- if ((val = zend_hash_find (control_ht , ZSTR_KNOWN (ZEND_STR_VALUE ))) != NULL ) {
454
+ val = zend_hash_find (control_ht , ZSTR_KNOWN (ZEND_STR_VALUE ));
455
+ if (val != NULL ) {
455
456
if (Z_TYPE_P (val ) != IS_ARRAY ) {
456
457
tmpstring = zval_get_string (val );
457
458
if (EG (exception )) {
@@ -461,13 +462,14 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
461
462
control_value .bv_val = ZSTR_VAL (tmpstring );
462
463
control_value .bv_len = ZSTR_LEN (tmpstring );
463
464
} else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_PAGEDRESULTS )) {
464
- zval * tmp ;
465
+ zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "size" , sizeof ( "size" ) - 1 ) ;
465
466
int pagesize = 1 ;
466
467
struct berval cookie = { 0L , NULL };
467
- if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "size" , sizeof ( "size" ) - 1 )) != NULL ) {
468
+ if (tmp != NULL ) {
468
469
pagesize = zval_get_long (tmp );
469
470
}
470
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "cookie" , sizeof ("cookie" ) - 1 )) != NULL ) {
471
+ tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "cookie" , sizeof ("cookie" ) - 1 );
472
+ if (tmp != NULL ) {
471
473
tmpstring = zval_get_string (tmp );
472
474
if (EG (exception )) {
473
475
rc = -1 ;
@@ -483,8 +485,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
483
485
php_error_docref (NULL , E_WARNING , "Failed to create paged result control value: %s (%d)" , ldap_err2string (rc ), rc );
484
486
}
485
487
} else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_ASSERT )) {
486
- zval * tmp ;
487
- if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 )) == NULL ) {
488
+ zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 ) ;
489
+ if (tmp == NULL ) {
488
490
rc = -1 ;
489
491
zend_value_error ("%s(): Control must have a \"filter\" key" , get_active_function_name ());
490
492
} else {
@@ -506,8 +508,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
506
508
zend_string_release (assert );
507
509
}
508
510
} else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_VALUESRETURNFILTER )) {
509
- zval * tmp ;
510
- if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 )) == NULL ) {
511
+ zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 ) ;
512
+ if (tmp == NULL ) {
511
513
rc = -1 ;
512
514
zend_value_error ("%s(): Control must have a \"filter\" key" , get_active_function_name ());
513
515
} else {
@@ -530,8 +532,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
530
532
}
531
533
}
532
534
} else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_PRE_READ ) || zend_string_equals_literal (control_oid , LDAP_CONTROL_POST_READ )) {
533
- zval * tmp ;
534
- if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "attrs" , sizeof ( "attrs" ) - 1 )) == NULL ) {
535
+ zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "attrs" , sizeof ( "attrs" ) - 1 ) ;
536
+ if (tmp == NULL ) {
535
537
rc = -1 ;
536
538
zend_value_error ("%s(): Control must have an \"attrs\" key" , get_active_function_name ());
537
539
} else {
@@ -541,15 +543,14 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
541
543
rc = -1 ;
542
544
php_error_docref (NULL , E_WARNING , "Failed to allocate control value" );
543
545
} else {
544
- zval * attr ;
545
-
546
546
uint32_t num_attribs = zend_hash_num_elements (Z_ARRVAL_P (tmp ));
547
547
ldap_attrs = safe_emalloc ((num_attribs + 1 ), sizeof (char * ), 0 );
548
548
tmpstrings1 = safe_emalloc (num_attribs , sizeof (zend_string * ), 0 );
549
549
num_tmpstrings1 = 0 ;
550
550
551
551
for (uint32_t i = 0 ; i < num_attribs ; i ++ ) {
552
- if ((attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i )) == NULL ) {
552
+ zval * attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i );
553
+ if (attr == NULL ) {
553
554
rc = -1 ;
554
555
php_error_docref (NULL , E_WARNING , "Failed to encode attribute list" );
555
556
goto failure ;
@@ -581,8 +582,6 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
581
582
}
582
583
}
583
584
} else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_SORTREQUEST )) {
584
- zval * sortkey , * tmp ;
585
-
586
585
uint32_t num_keys = zend_hash_num_elements (Z_ARRVAL_P (val ));
587
586
sort_keys = safe_emalloc ((num_keys + 1 ), sizeof (LDAPSortKey * ), 0 );
588
587
tmpstrings1 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
@@ -591,13 +590,15 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
591
590
num_tmpstrings2 = 0 ;
592
591
593
592
for (uint32_t i = 0 ; i < num_keys ; i ++ ) {
594
- if ((sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i )) == NULL ) {
593
+ zval * sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i );
594
+ if (sortkey == NULL ) {
595
595
rc = -1 ;
596
596
php_error_docref (NULL , E_WARNING , "Failed to encode sort keys list" );
597
597
goto failure ;
598
598
}
599
599
600
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "attr" , sizeof ("attr" ) - 1 )) == NULL ) {
600
+ zval * tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "attr" , sizeof ("attr" ) - 1 );
601
+ if (tmp == NULL ) {
601
602
rc = -1 ;
602
603
zend_value_error ("%s(): Sort key list must have an \"attr\" key" , get_active_function_name ());
603
604
goto failure ;
@@ -611,7 +612,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
611
612
sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
612
613
++ num_tmpstrings1 ;
613
614
614
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 )) != NULL ) {
615
+ tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 );
616
+ if (tmp == NULL ) {
615
617
tmpstrings2 [num_tmpstrings2 ] = zval_get_string (tmp );
616
618
if (EG (exception )) {
617
619
rc = -1 ;
@@ -623,7 +625,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
623
625
sort_keys [i ]-> orderingRule = NULL ;
624
626
}
625
627
626
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "reverse" , sizeof ("reverse" ) - 1 )) != NULL ) {
628
+ tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "reverse" , sizeof ("reverse" ) - 1 );
629
+ if (tmp == NULL ) {
627
630
sort_keys [i ]-> reverseOrder = zend_is_true (tmp );
628
631
} else {
629
632
sort_keys [i ]-> reverseOrder = 0 ;
@@ -637,28 +640,30 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
637
640
php_error_docref (NULL , E_WARNING , "Failed to create sort control value: %s (%d)" , ldap_err2string (rc ), rc );
638
641
}
639
642
} else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_VLVREQUEST )) {
640
- zval * tmp ;
641
643
LDAPVLVInfo vlvInfo ;
642
644
struct berval attrValue ;
643
645
struct berval context ;
644
646
645
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "before" , sizeof ("before" ) - 1 )) != NULL ) {
647
+ zval * tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "before" , sizeof ("before" ) - 1 );
648
+ if (tmp != NULL ) {
646
649
vlvInfo .ldvlv_before_count = zval_get_long (tmp );
647
650
} else {
648
651
rc = -1 ;
649
652
zend_value_error ("%s(): Array value for VLV control must have a \"before\" key" , get_active_function_name ());
650
653
goto failure ;
651
654
}
652
655
653
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "after" , sizeof ("after" ) - 1 )) != NULL ) {
656
+ tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "after" , sizeof ("after" ) - 1 );
657
+ if (tmp != NULL ) {
654
658
vlvInfo .ldvlv_after_count = zval_get_long (tmp );
655
659
} else {
656
660
rc = -1 ;
657
661
zend_value_error ("%s(): Array value for VLV control must have an \"after\" key" , get_active_function_name ());
658
662
goto failure ;
659
663
}
660
664
661
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "attrvalue" , sizeof ("attrvalue" ) - 1 )) != NULL ) {
665
+ tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "attrvalue" , sizeof ("attrvalue" ) - 1 );
666
+ if (tmp != NULL ) {
662
667
tmpstring = zval_get_string (tmp );
663
668
if (EG (exception )) {
664
669
rc = -1 ;
@@ -671,8 +676,9 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
671
676
vlvInfo .ldvlv_attrvalue = NULL ;
672
677
vlvInfo .ldvlv_offset = zval_get_long (tmp );
673
678
/* Find "count" key */
674
- if ((tmp = zend_hash_find (Z_ARRVAL_P (val ), ZSTR_KNOWN (ZEND_STR_COUNT ))) != NULL ) {
675
- vlvInfo .ldvlv_count = zval_get_long (tmp );
679
+ zval * count_key = zend_hash_find (Z_ARRVAL_P (val ), ZSTR_KNOWN (ZEND_STR_COUNT ));
680
+ if (count_key != NULL ) {
681
+ vlvInfo .ldvlv_count = zval_get_long (count_key );
676
682
} else {
677
683
rc = -1 ;
678
684
zend_value_error ("%s(): Array value for VLV control must have a \"count\" key" , get_active_function_name ());
@@ -684,7 +690,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
684
690
goto failure ;
685
691
}
686
692
687
- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "context" , sizeof ("context" ) - 1 )) != NULL ) {
693
+ tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "context" , sizeof ("context" ) - 1 );
694
+ if (tmp != NULL ) {
688
695
tmpstring = zval_get_string (tmp );
689
696
if (EG (exception )) {
690
697
rc = -1 ;
@@ -1852,7 +1859,6 @@ PHP_FUNCTION(ldap_first_entry)
1852
1859
zval * link , * result ;
1853
1860
ldap_linkdata * ld ;
1854
1861
ldap_resultdata * ldap_result ;
1855
- LDAPMessage * entry ;
1856
1862
1857
1863
if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result , ldap_result_ce ) != SUCCESS ) {
1858
1864
RETURN_THROWS ();
@@ -1864,7 +1870,8 @@ PHP_FUNCTION(ldap_first_entry)
1864
1870
ldap_result = Z_LDAP_RESULT_P (result );
1865
1871
VERIFY_LDAP_RESULT_OPEN (ldap_result );
1866
1872
1867
- if ((entry = ldap_first_entry (ld -> link , ldap_result -> result )) == NULL ) {
1873
+ LDAPMessage * entry = ldap_first_entry (ld -> link , ldap_result -> result );
1874
+ if (entry == NULL ) {
1868
1875
RETVAL_FALSE ;
1869
1876
} else {
1870
1877
object_init_ex (return_value , ldap_result_entry_ce );
@@ -1882,7 +1889,6 @@ PHP_FUNCTION(ldap_next_entry)
1882
1889
zval * link , * result_entry ;
1883
1890
ldap_linkdata * ld ;
1884
1891
ldap_result_entry * resultentry ;
1885
- LDAPMessage * entry_next ;
1886
1892
1887
1893
if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
1888
1894
RETURN_THROWS ();
@@ -1893,7 +1899,8 @@ PHP_FUNCTION(ldap_next_entry)
1893
1899
1894
1900
resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
1895
1901
1896
- if ((entry_next = ldap_next_entry (ld -> link , resultentry -> data )) == NULL ) {
1902
+ LDAPMessage * entry_next = ldap_next_entry (ld -> link , resultentry -> data );
1903
+ if (entry_next == NULL ) {
1897
1904
RETVAL_FALSE ;
1898
1905
} else {
1899
1906
object_init_ex (return_value , ldap_result_entry_ce );
@@ -2010,7 +2017,6 @@ PHP_FUNCTION(ldap_first_attribute)
2010
2017
zval * link , * result_entry ;
2011
2018
ldap_linkdata * ld ;
2012
2019
ldap_result_entry * resultentry ;
2013
- char * attribute ;
2014
2020
2015
2021
if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
2016
2022
RETURN_THROWS ();
@@ -2021,7 +2027,8 @@ PHP_FUNCTION(ldap_first_attribute)
2021
2027
2022
2028
resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
2023
2029
2024
- if ((attribute = ldap_first_attribute (ld -> link , resultentry -> data , & resultentry -> ber )) == NULL ) {
2030
+ char * attribute = ldap_first_attribute (ld -> link , resultentry -> data , & resultentry -> ber );
2031
+ if (attribute == NULL ) {
2025
2032
RETURN_FALSE ;
2026
2033
} else {
2027
2034
RETVAL_STRING (attribute );
@@ -2038,7 +2045,6 @@ PHP_FUNCTION(ldap_next_attribute)
2038
2045
zval * link , * result_entry ;
2039
2046
ldap_linkdata * ld ;
2040
2047
ldap_result_entry * resultentry ;
2041
- char * attribute ;
2042
2048
2043
2049
if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
2044
2050
RETURN_THROWS ();
@@ -2054,7 +2060,8 @@ PHP_FUNCTION(ldap_next_attribute)
2054
2060
RETURN_FALSE ;
2055
2061
}
2056
2062
2057
- if ((attribute = ldap_next_attribute (ld -> link , resultentry -> data , resultentry -> ber )) == NULL ) {
2063
+ char * attribute = ldap_next_attribute (ld -> link , resultentry -> data , resultentry -> ber );
2064
+ if (attribute == NULL ) {
2058
2065
#if (LDAP_API_VERSION > 2000 ) || defined(HAVE_ORALDAP )
2059
2066
if (resultentry -> ber != NULL ) {
2060
2067
ber_free (resultentry -> ber , 0 );
@@ -2132,7 +2139,6 @@ PHP_FUNCTION(ldap_get_values_len)
2132
2139
ldap_linkdata * ld ;
2133
2140
ldap_result_entry * resultentry ;
2134
2141
char * attr ;
2135
- struct berval * * ldap_value_len ;
2136
2142
int num_values ;
2137
2143
size_t attr_len ;
2138
2144
@@ -2145,7 +2151,8 @@ PHP_FUNCTION(ldap_get_values_len)
2145
2151
2146
2152
resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
2147
2153
2148
- if ((ldap_value_len = ldap_get_values_len (ld -> link , resultentry -> data , attr )) == NULL ) {
2154
+ struct berval * * ldap_value_len = ldap_get_values_len (ld -> link , resultentry -> data , attr );
2155
+ if (ldap_value_len == NULL ) {
2149
2156
php_error_docref (NULL , E_WARNING , "Cannot get the value(s) of attribute %s" , ldap_err2string (_get_lderrno (ld -> link )));
2150
2157
RETURN_FALSE ;
2151
2158
}
@@ -2198,14 +2205,15 @@ PHP_FUNCTION(ldap_get_dn)
2198
2205
PHP_FUNCTION (ldap_explode_dn )
2199
2206
{
2200
2207
zend_long with_attrib ;
2201
- char * dn , * * ldap_value ;
2208
+ char * dn ;
2202
2209
size_t dn_len ;
2203
2210
2204
2211
if (zend_parse_parameters (ZEND_NUM_ARGS (), "pl" , & dn , & dn_len , & with_attrib ) != SUCCESS ) {
2205
2212
RETURN_THROWS ();
2206
2213
}
2207
2214
2208
- if (!(ldap_value = ldap_explode_dn (dn , with_attrib ))) {
2215
+ char * * ldap_value = ldap_explode_dn (dn , with_attrib );
2216
+ if (ldap_value == NULL ) {
2209
2217
/* Invalid parameters were passed to ldap_explode_dn */
2210
2218
RETURN_FALSE ;
2211
2219
}
@@ -3500,7 +3508,6 @@ PHP_FUNCTION(ldap_first_reference)
3500
3508
zval * link , * result ;
3501
3509
ldap_linkdata * ld ;
3502
3510
ldap_resultdata * ldap_result ;
3503
- LDAPMessage * entry ;
3504
3511
3505
3512
if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result , ldap_result_ce ) != SUCCESS ) {
3506
3513
RETURN_THROWS ();
@@ -3512,7 +3519,8 @@ PHP_FUNCTION(ldap_first_reference)
3512
3519
ldap_result = Z_LDAP_RESULT_P (result );
3513
3520
VERIFY_LDAP_RESULT_OPEN (ldap_result );
3514
3521
3515
- if ((entry = ldap_first_reference (ld -> link , ldap_result -> result )) == NULL ) {
3522
+ LDAPMessage * entry = ldap_first_reference (ld -> link , ldap_result -> result );
3523
+ if (entry == NULL ) {
3516
3524
RETVAL_FALSE ;
3517
3525
} else {
3518
3526
object_init_ex (return_value , ldap_result_entry_ce );
@@ -3530,7 +3538,6 @@ PHP_FUNCTION(ldap_next_reference)
3530
3538
zval * link , * result_entry ;
3531
3539
ldap_linkdata * ld ;
3532
3540
ldap_result_entry * resultentry ;
3533
- LDAPMessage * entry_next ;
3534
3541
3535
3542
if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
3536
3543
RETURN_THROWS ();
@@ -3541,7 +3548,8 @@ PHP_FUNCTION(ldap_next_reference)
3541
3548
3542
3549
resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
3543
3550
3544
- if ((entry_next = ldap_next_reference (ld -> link , resultentry -> data )) == NULL ) {
3551
+ LDAPMessage * entry_next = ldap_first_reference (ld -> link , resultentry -> data );
3552
+ if (entry_next == NULL ) {
3545
3553
RETVAL_FALSE ;
3546
3554
} else {
3547
3555
object_init_ex (return_value , ldap_result_entry_ce );
0 commit comments