@@ -2533,112 +2533,110 @@ PHP_FUNCTION(ldap_modify_batch)
25332533	VERIFY_LDAP_LINK_CONNECTED (ld );
25342534
25352535	/* perform validation */ 
2536- 	{
2537- 		/* make sure the DN contains no NUL bytes */ 
2538- 		if  (zend_char_has_nul_byte (dn , dn_len )) {
2539- 			zend_argument_value_error (2 , "must not contain null bytes" );
2536+ 	/* make sure the DN contains no NUL bytes */ 
2537+ 	if  (zend_char_has_nul_byte (dn , dn_len )) {
2538+ 		zend_argument_value_error (2 , "must not contain null bytes" );
2539+ 		RETURN_THROWS ();
2540+ 	}
2541+ 
2542+ 	/* make sure the top level is a normal array */ 
2543+ 	if  (zend_hash_num_elements (modifications ) ==  0 ) {
2544+ 		zend_argument_must_not_be_empty_error (3 );
2545+ 		RETURN_THROWS ();
2546+ 	}
2547+ 	if  (!zend_array_is_list (modifications )) {
2548+ 		zend_argument_value_error (3 , "must be a list" );
2549+ 		RETURN_THROWS ();
2550+ 	}
2551+ 
2552+ 	zval  * modification_zv  =  NULL ;
2553+ 	ZEND_HASH_FOREACH_VAL (modifications , modification_zv ) {
2554+ 		if  (Z_TYPE_P (modification_zv ) !=  IS_ARRAY ) {
2555+ 			zend_argument_type_error (3 , "must only contain arrays" );
25402556			RETURN_THROWS ();
25412557		}
25422558
2543- 		/* make sure the top level is a normal array */ 
2544- 		if  (zend_hash_num_elements (modifications ) ==  0 ) {
2545- 			zend_argument_must_not_be_empty_error (3 );
2559+ 		SEPARATE_ARRAY (modification_zv );
2560+ 		const  HashTable  * modification  =  Z_ARRVAL_P (modification_zv );
2561+ 		uint32_t  modification_size  =  zend_hash_num_elements (modification );
2562+ 
2563+ 		if  (modification_size  !=  2  &&  modification_size  !=  3 ) {
2564+ 			zend_argument_value_error (3 , "a modification entry must only contain the keys " 
2565+ 				"\""  LDAP_MODIFY_BATCH_ATTRIB  "\", \""  LDAP_MODIFY_BATCH_MODTYPE  "\", and \""  LDAP_MODIFY_BATCH_VALUES  "\"" );
25462566			RETURN_THROWS ();
25472567		}
2548- 		if  (!zend_array_is_list (modifications )) {
2549- 			zend_argument_value_error (3 , "must be a list" );
2568+ 
2569+ 		const  zval  * attrib  =  zend_hash_str_find (modification , LDAP_MODIFY_BATCH_ATTRIB , strlen (LDAP_MODIFY_BATCH_ATTRIB ));
2570+ 		if  (UNEXPECTED (attrib  ==  NULL )) {
2571+ 			zend_argument_value_error (3 , "a modification entry must contain the \""  LDAP_MODIFY_BATCH_ATTRIB  "\" option" );
2572+ 			RETURN_THROWS ();
2573+ 		}
2574+ 		if  (UNEXPECTED (Z_TYPE_P (attrib ) !=  IS_STRING )) {
2575+ 			zend_argument_type_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_ATTRIB  "\" must be of type string, %s given" , zend_zval_value_name (attrib ));
2576+ 			RETURN_THROWS ();
2577+ 		}
2578+ 		if  (zend_str_has_nul_byte (Z_STR_P (attrib ))) {
2579+ 			zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_ATTRIB  "\" must not contain null bytes" );
25502580			RETURN_THROWS ();
25512581		}
25522582
2553- 		zval  * modification_zv  =  NULL ;
2554- 		ZEND_HASH_FOREACH_VAL (modifications , modification_zv ) {
2555- 			if  (Z_TYPE_P (modification_zv ) !=  IS_ARRAY ) {
2556- 				zend_argument_type_error (3 , "must only contain arrays" );
2557- 				RETURN_THROWS ();
2558- 			}
2559- 
2560- 			SEPARATE_ARRAY (modification_zv );
2561- 			const  HashTable  * modification  =  Z_ARRVAL_P (modification_zv );
2562- 			uint32_t  modification_size  =  zend_hash_num_elements (modification );
2563- 
2564- 			if  (modification_size  !=  2  &&  modification_size  !=  3 ) {
2565- 				zend_argument_value_error (3 , "a modification entry must only contain the keys " 
2566- 					"\""  LDAP_MODIFY_BATCH_ATTRIB  "\", \""  LDAP_MODIFY_BATCH_MODTYPE  "\", and \""  LDAP_MODIFY_BATCH_VALUES  "\"" );
2567- 				RETURN_THROWS ();
2568- 			}
2569- 
2570- 			const  zval  * attrib  =  zend_hash_str_find (modification , LDAP_MODIFY_BATCH_ATTRIB , strlen (LDAP_MODIFY_BATCH_ATTRIB ));
2571- 			if  (UNEXPECTED (attrib  ==  NULL )) {
2572- 				zend_argument_value_error (3 , "a modification entry must contain the \""  LDAP_MODIFY_BATCH_ATTRIB  "\" option" );
2573- 				RETURN_THROWS ();
2574- 			}
2575- 			if  (UNEXPECTED (Z_TYPE_P (attrib ) !=  IS_STRING )) {
2576- 				zend_argument_type_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_ATTRIB  "\" must be of type string, %s given" , zend_zval_value_name (attrib ));
2577- 				RETURN_THROWS ();
2578- 			}
2579- 			if  (zend_str_has_nul_byte (Z_STR_P (attrib ))) {
2580- 				zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_ATTRIB  "\" must not contain null bytes" );
2581- 				RETURN_THROWS ();
2582- 			}
2583- 
2584- 			const  zval  * modtype_zv  =  zend_hash_str_find (modification , LDAP_MODIFY_BATCH_MODTYPE , strlen (LDAP_MODIFY_BATCH_MODTYPE ));
2585- 			if  (UNEXPECTED (modtype_zv  ==  NULL )) {
2586- 				zend_argument_value_error (3 , "a modification entry must contain the \""  LDAP_MODIFY_BATCH_MODTYPE  "\" option" );
2587- 				RETURN_THROWS ();
2588- 			}
2589- 			if  (UNEXPECTED (Z_TYPE_P (modtype_zv ) !=  IS_LONG )) {
2590- 				zend_argument_type_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_MODTYPE  "\" must be of type int, %s given" , zend_zval_value_name (attrib ));
2591- 				RETURN_THROWS ();
2592- 			}
2593- 			zend_long  modtype  =  Z_LVAL_P (modtype_zv );
2594- 			if  (
2595- 				modtype  !=  LDAP_MODIFY_BATCH_ADD  && 
2596- 				modtype  !=  LDAP_MODIFY_BATCH_REMOVE  && 
2597- 				modtype  !=  LDAP_MODIFY_BATCH_REPLACE  && 
2598- 				modtype  !=  LDAP_MODIFY_BATCH_REMOVE_ALL 
2599- 			) {
2600- 				zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_MODTYPE  "\" must be" 
2601- 					" LDAP_MODIFY_BATCH_ADD, LDAP_MODIFY_BATCH_REMOVE, LDAP_MODIFY_BATCH_REPLACE," 
2602- 					" or LDAP_MODIFY_BATCH_REMOVE_ALL" );
2603- 				RETURN_THROWS ();
2604- 			}
2605- 			/* We assume that the modification array is well-formed and only ever contains an extra "values" key */ 
2606- 			if  (modtype  ==  LDAP_MODIFY_BATCH_REMOVE_ALL  &&  modification_size  ==  3 ) {
2607- 				zend_argument_value_error (3 , "a modification entry must not contain the " 
2608- 					"\""  LDAP_MODIFY_BATCH_VALUES  "\" option when option \""  LDAP_MODIFY_BATCH_MODTYPE  "\" " 
2609- 					"is LDAP_MODIFY_BATCH_REMOVE_ALL" );
2610- 				RETURN_THROWS ();
2611- 			}
2583+ 		const  zval  * modtype_zv  =  zend_hash_str_find (modification , LDAP_MODIFY_BATCH_MODTYPE , strlen (LDAP_MODIFY_BATCH_MODTYPE ));
2584+ 		if  (UNEXPECTED (modtype_zv  ==  NULL )) {
2585+ 			zend_argument_value_error (3 , "a modification entry must contain the \""  LDAP_MODIFY_BATCH_MODTYPE  "\" option" );
2586+ 			RETURN_THROWS ();
2587+ 		}
2588+ 		if  (UNEXPECTED (Z_TYPE_P (modtype_zv ) !=  IS_LONG )) {
2589+ 			zend_argument_type_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_MODTYPE  "\" must be of type int, %s given" , zend_zval_value_name (attrib ));
2590+ 			RETURN_THROWS ();
2591+ 		}
2592+ 		zend_long  modtype  =  Z_LVAL_P (modtype_zv );
2593+ 		if  (
2594+ 			modtype  !=  LDAP_MODIFY_BATCH_ADD  && 
2595+ 			modtype  !=  LDAP_MODIFY_BATCH_REMOVE  && 
2596+ 			modtype  !=  LDAP_MODIFY_BATCH_REPLACE  && 
2597+ 			modtype  !=  LDAP_MODIFY_BATCH_REMOVE_ALL 
2598+ 		) {
2599+ 			zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_MODTYPE  "\" must be" 
2600+ 				" LDAP_MODIFY_BATCH_ADD, LDAP_MODIFY_BATCH_REMOVE, LDAP_MODIFY_BATCH_REPLACE," 
2601+ 				" or LDAP_MODIFY_BATCH_REMOVE_ALL" );
2602+ 			RETURN_THROWS ();
2603+ 		}
2604+ 		/* We assume that the modification array is well-formed and only ever contains an extra "values" key */ 
2605+ 		if  (modtype  ==  LDAP_MODIFY_BATCH_REMOVE_ALL  &&  modification_size  ==  3 ) {
2606+ 			zend_argument_value_error (3 , "a modification entry must not contain the " 
2607+ 				"\""  LDAP_MODIFY_BATCH_VALUES  "\" option when option \""  LDAP_MODIFY_BATCH_MODTYPE  "\" " 
2608+ 				"is LDAP_MODIFY_BATCH_REMOVE_ALL" );
2609+ 			RETURN_THROWS ();
2610+ 		}
26122611
2613- 			zval  * modification_values_zv  =  zend_hash_str_find (modification , LDAP_MODIFY_BATCH_VALUES , strlen (LDAP_MODIFY_BATCH_VALUES ));
2614- 			if  (modification_values_zv  ==  NULL ) {
2615- 				if  (modtype  !=  LDAP_MODIFY_BATCH_REMOVE_ALL ) {
2616- 					zend_argument_value_error (3 , "a modification entry must contain the " 
2617- 						"\""  LDAP_MODIFY_BATCH_VALUES  "\" option when the \""  LDAP_MODIFY_BATCH_MODTYPE  "\" option " 
2618- 						"is not LDAP_MODIFY_BATCH_REMOVE_ALL" );
2619- 					RETURN_THROWS ();
2620- 				}
2621- 				continue ;
2622- 			}
2623- 			if  (Z_TYPE_P (modification_values_zv ) !=  IS_ARRAY ) {
2624- 				zend_argument_type_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_VALUES  "\" must be of type array, %s given" , zend_zval_value_name (attrib ));
2612+ 		zval  * modification_values_zv  =  zend_hash_str_find (modification , LDAP_MODIFY_BATCH_VALUES , strlen (LDAP_MODIFY_BATCH_VALUES ));
2613+ 		if  (modification_values_zv  ==  NULL ) {
2614+ 			if  (modtype  !=  LDAP_MODIFY_BATCH_REMOVE_ALL ) {
2615+ 				zend_argument_value_error (3 , "a modification entry must contain the " 
2616+ 					"\""  LDAP_MODIFY_BATCH_VALUES  "\" option when the \""  LDAP_MODIFY_BATCH_MODTYPE  "\" option " 
2617+ 					"is not LDAP_MODIFY_BATCH_REMOVE_ALL" );
26252618				RETURN_THROWS ();
26262619			}
2620+ 			continue ;
2621+ 		}
2622+ 		if  (Z_TYPE_P (modification_values_zv ) !=  IS_ARRAY ) {
2623+ 			zend_argument_type_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_VALUES  "\" must be of type array, %s given" , zend_zval_value_name (attrib ));
2624+ 			RETURN_THROWS ();
2625+ 		}
26272626
2628- 			SEPARATE_ARRAY (modification_values_zv );
2629- 			const  HashTable  * modification_values  =  Z_ARRVAL_P (modification_values_zv );
2630- 			/* is the array not empty? */ 
2631- 			uint32_t  num_modvals  =  zend_hash_num_elements (modification_values );
2632- 			if  (num_modvals  ==  0 ) {
2633- 				zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_VALUES  "\" must not be empty" );
2634- 				RETURN_THROWS ();
2635- 			}
2636- 			if  (!zend_array_is_list (modification_values )) {
2637- 				zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_VALUES  "\" must be a list" );
2638- 				RETURN_THROWS ();
2639- 			}
2640- 		} ZEND_HASH_FOREACH_END ();
2641- 	}
2627+ 		SEPARATE_ARRAY (modification_values_zv );
2628+ 		const  HashTable  * modification_values  =  Z_ARRVAL_P (modification_values_zv );
2629+ 		/* is the array not empty? */ 
2630+ 		uint32_t  num_modvals  =  zend_hash_num_elements (modification_values );
2631+ 		if  (num_modvals  ==  0 ) {
2632+ 			zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_VALUES  "\" must not be empty" );
2633+ 			RETURN_THROWS ();
2634+ 		}
2635+ 		if  (!zend_array_is_list (modification_values )) {
2636+ 			zend_argument_value_error (3 , "the value for option \""  LDAP_MODIFY_BATCH_VALUES  "\" must be a list" );
2637+ 			RETURN_THROWS ();
2638+ 		}
2639+ 	} ZEND_HASH_FOREACH_END ();
26422640	/* validation was successful */ 
26432641
26442642	/* allocate array of modifications */ 
@@ -2647,7 +2645,6 @@ PHP_FUNCTION(ldap_modify_batch)
26472645
26482646	/* for each modification */ 
26492647	zend_ulong  modification_index  =  0 ;
2650- 	zval  * modification_zv  =  NULL ;
26512648	ZEND_HASH_FOREACH_NUM_KEY_VAL (modifications , modification_index , modification_zv ) {
26522649		ldap_mods [modification_index ] =  safe_emalloc (1 , sizeof (LDAPMod ), 0 );
26532650
0 commit comments