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