@@ -538,6 +538,19 @@ static struct php_proc_open_descriptor_item* alloc_descriptor_array(zval *descri
538
538
return ecalloc (sizeof (struct php_proc_open_descriptor_item ), ndescriptors );
539
539
}
540
540
541
+ static int get_string_parameter (zval * * dest , zval * array , int index , char * param_name )
542
+ {
543
+ if ((* dest = zend_hash_index_find (Z_ARRVAL_P (array ), index )) == NULL ) {
544
+ zend_value_error ("Missing %s" , param_name );
545
+ return FAILURE ;
546
+ }
547
+ if (!try_convert_to_string (* dest )) {
548
+ return FAILURE ;
549
+ }
550
+
551
+ return SUCCESS ;
552
+ }
553
+
541
554
static int set_proc_descriptor_to_blackhole (struct php_proc_open_descriptor_item * desc )
542
555
{
543
556
#ifdef PHP_WIN32
@@ -831,26 +844,13 @@ PHP_FUNCTION(proc_open)
831
844
} else if (Z_TYPE_P (descitem ) != IS_ARRAY ) {
832
845
zend_argument_value_error (2 , "must only contain arrays and File-Handles" );
833
846
goto exit_fail ;
834
- } else {
835
-
836
- if ((ztype = zend_hash_index_find (Z_ARRVAL_P (descitem ), 0 )) != NULL ) {
837
- if (!try_convert_to_string (ztype )) {
838
- goto exit_fail ;
839
- }
840
- } else {
841
- zend_value_error ("Missing handle qualifier in array" );
847
+ } else if (get_string_parameter (& ztype , descitem , 0 , "handle qualifier" ) == FAILURE ) {
842
848
goto exit_fail ;
843
- }
844
-
849
+ } else {
845
850
if (strcmp (Z_STRVAL_P (ztype ), "pipe" ) == 0 ) {
846
851
zval * zmode ;
847
852
848
- if ((zmode = zend_hash_index_find (Z_ARRVAL_P (descitem ), 1 )) != NULL ) {
849
- if (!try_convert_to_string (zmode )) {
850
- goto exit_fail ;
851
- }
852
- } else {
853
- zend_value_error ("Missing mode parameter for 'pipe'" );
853
+ if (get_string_parameter (& zmode , descitem , 1 , "mode parameter for 'pipe'" ) == FAILURE ) {
854
854
goto exit_fail ;
855
855
}
856
856
@@ -860,21 +860,10 @@ PHP_FUNCTION(proc_open)
860
860
} else if (strcmp (Z_STRVAL_P (ztype ), "file" ) == 0 ) {
861
861
zval * zfile , * zmode ;
862
862
863
- if ((zfile = zend_hash_index_find (Z_ARRVAL_P (descitem ), 1 )) != NULL ) {
864
- if (!try_convert_to_string (zfile )) {
865
- goto exit_fail ;
866
- }
867
- } else {
868
- zend_value_error ("Missing file name parameter for 'file'" );
863
+ if (get_string_parameter (& zfile , descitem , 1 , "file name parameter for 'file'" ) == FAILURE ) {
869
864
goto exit_fail ;
870
865
}
871
-
872
- if ((zmode = zend_hash_index_find (Z_ARRVAL_P (descitem ), 2 )) != NULL ) {
873
- if (!try_convert_to_string (zmode )) {
874
- goto exit_fail ;
875
- }
876
- } else {
877
- zend_value_error ("Missing mode parameter for 'file'" );
866
+ if (get_string_parameter (& zmode , descitem , 2 , "mode parameter for 'file'" ) == FAILURE ) {
878
867
goto exit_fail ;
879
868
}
880
869
0 commit comments