]> granicus.if.org Git - php/commitdiff
Promote warnings to exceptions in proc_open() function
authorMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 20 Nov 2019 01:30:48 +0000 (02:30 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 20 Dec 2019 15:43:40 +0000 (16:43 +0100)
GH-5004

ext/standard/proc_open.c
ext/standard/tests/general_functions/proc_open_array.phpt
ext/standard/tests/general_functions/proc_open_pipes3.phpt
ext/standard/tests/general_functions/proc_open_redirect.phpt

index 4906b3f8283754abf38f5161e73a47897c14b9ad..85bd2c9f57c8e00a5dfc43a7267a017d2b379815 100644 (file)
@@ -529,8 +529,8 @@ PHP_FUNCTION(proc_open)
                zval *arg_zv;
                uint32_t num_elems = zend_hash_num_elements(Z_ARRVAL_P(command_zv));
                if (num_elems == 0) {
-                       php_error_docref(NULL, E_WARNING, "Command array must have at least one element");
-                       RETURN_FALSE;
+                       zend_value_error("Command array must have at least one element");
+                       return;
                }
 
 #ifdef PHP_WIN32
@@ -622,7 +622,7 @@ PHP_FUNCTION(proc_open)
                zval *ztype;
 
                if (str_index) {
-                       php_error_docref(NULL, E_WARNING, "descriptor spec must be an integer indexed array");
+                       zend_value_error("Descriptor spec must be an integer indexed array");
                        goto exit_fail;
                }
 
@@ -655,7 +655,7 @@ PHP_FUNCTION(proc_open)
                        descriptors[ndesc].mode = DESC_FILE;
 
                } else if (Z_TYPE_P(descitem) != IS_ARRAY) {
-                       php_error_docref(NULL, E_WARNING, "Descriptor item must be either an array or a File-Handle");
+                       zend_value_error("Descriptor item must be either an array or a File-Handle");
                        goto exit_fail;
                } else {
 
@@ -664,7 +664,7 @@ PHP_FUNCTION(proc_open)
                                        goto exit_fail;
                                }
                        } else {
-                               php_error_docref(NULL, E_WARNING, "Missing handle qualifier in array");
+                               zend_value_error("Missing handle qualifier in array");
                                goto exit_fail;
                        }
 
@@ -677,7 +677,7 @@ PHP_FUNCTION(proc_open)
                                                goto exit_fail;
                                        }
                                } else {
-                                       php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'pipe'");
+                                       zend_value_error("Missing mode parameter for 'pipe'");
                                        goto exit_fail;
                                }
 
@@ -718,7 +718,7 @@ PHP_FUNCTION(proc_open)
                                                goto exit_fail;
                                        }
                                } else {
-                                       php_error_docref(NULL, E_WARNING, "Missing file name parameter for 'file'");
+                                       zend_value_error("Missing file name parameter for 'file'");
                                        goto exit_fail;
                                }
 
@@ -727,7 +727,7 @@ PHP_FUNCTION(proc_open)
                                                goto exit_fail;
                                        }
                                } else {
-                                       php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'file'");
+                                       zend_value_error("Missing mode parameter for 'file'");
                                        goto exit_fail;
                                }
 
@@ -760,11 +760,11 @@ PHP_FUNCTION(proc_open)
                                php_file_descriptor_t childend;
 
                                if (!ztarget) {
-                                       php_error_docref(NULL, E_WARNING, "Missing redirection target");
+                                       zend_value_error("Missing redirection target");
                                        goto exit_fail;
                                }
                                if (Z_TYPE_P(ztarget) != IS_LONG) {
-                                       php_error_docref(NULL, E_WARNING, "Redirection target must be an integer");
+                                       zend_value_error("Redirection target must be an integer");
                                        goto exit_fail;
                                }
 
index 8b42a55bacaf626e08395329c96826477c31760e..99e1cc56cb4d355713980299708296ee8aeaf4e9 100644 (file)
@@ -10,8 +10,12 @@ $ds = [
     2 => ['pipe', 'w'],
 ];
 
-echo "Empty command array:";
-var_dump(proc_open([], $ds, $pipes));
+echo "Empty command array:\n";
+try {
+    proc_open([], $ds, $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
 echo "\nNul byte in program name:";
 var_dump(proc_open(["php\0oops"], $ds, $pipes));
@@ -56,8 +60,7 @@ proc_close($proc);
 ?>
 --EXPECTF--
 Empty command array:
-Warning: proc_open(): Command array must have at least one element in %s on line %d
-bool(false)
+Command array must have at least one element
 
 Nul byte in program name:
 Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d
index 7671b1dce179478a4d5d7fcecc8659b69cf89f60..b83a0e1a07381928e5f7141b087a62f0a429d4f0 100644 (file)
@@ -14,7 +14,11 @@ $spec[$i] = array('pi');
 proc_open("$php -n $callee", $spec, $pipes);
 
 $spec[$i] = 1;
-proc_open("$php -n $callee", $spec, $pipes);
+try {
+    proc_open("$php -n $callee", $spec, $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
 $spec[$i] = array('pipe', "test");
 proc_open("$php -n $callee", $spec, $pipes);
@@ -28,8 +32,7 @@ echo "END\n";
 ?>
 --EXPECTF--
 Warning: proc_open(): pi is not a valid descriptor spec/mode in %s on line %d
-
-Warning: proc_open(): Descriptor item must be either an array or a File-Handle in %s on line %d
+Descriptor item must be either an array or a File-Handle
 array(4) {
   [3]=>
   resource(%d) of type (Unknown)
index 92da696ee9d98aacac4eba8183616474585781ae..bf0412c0a2f58d001890f744f86096cf4c9edd01 100644 (file)
@@ -4,9 +4,23 @@ Redirection support in proc_open
 <?php
 
 $php = getenv('TEST_PHP_EXECUTABLE');
-var_dump(proc_open([$php], [['redirect']], $pipes));
-var_dump(proc_open([$php], [['redirect', 'foo']], $pipes));
-var_dump(proc_open([$php], [['redirect', 42]], $pipes));
+try {
+    proc_open([$php], [['redirect']], $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    proc_open([$php], [['redirect', 'foo']], $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    proc_open([$php], [['redirect', 42]], $pipes);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
 
 echo "\nWith pipe:\n";
 $cmd = [$php, '-r', 'echo "Test\n"; fprintf(STDERR, "Error");'];
@@ -38,14 +52,10 @@ proc_close($proc);
 
 ?>
 --EXPECTF--
-Warning: proc_open(): Missing redirection target in %s on line %d
-bool(false)
-
-Warning: proc_open(): Redirection target must be an integer in %s on line %d
-bool(false)
+Missing redirection target
+Redirection target must be an integer
 
-Warning: proc_open(): Redirection target 42 not found in %s on line %d
-bool(false)
+Warning: proc_open(): Redirection target 42 not found in %s
 
 With pipe:
 array(1) {