Skip to content

Commit 17598d5

Browse files
committed
Promote warnings to exceptions in proc_open() function
GH-5004
1 parent a2d83a6 commit 17598d5

File tree

4 files changed

+43
-27
lines changed

4 files changed

+43
-27
lines changed

ext/standard/proc_open.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ PHP_FUNCTION(proc_open)
529529
zval *arg_zv;
530530
uint32_t num_elems = zend_hash_num_elements(Z_ARRVAL_P(command_zv));
531531
if (num_elems == 0) {
532-
php_error_docref(NULL, E_WARNING, "Command array must have at least one element");
533-
RETURN_FALSE;
532+
zend_value_error("Command array must have at least one element");
533+
return;
534534
}
535535

536536
#ifdef PHP_WIN32
@@ -622,7 +622,7 @@ PHP_FUNCTION(proc_open)
622622
zval *ztype;
623623

624624
if (str_index) {
625-
php_error_docref(NULL, E_WARNING, "descriptor spec must be an integer indexed array");
625+
zend_value_error("Descriptor spec must be an integer indexed array");
626626
goto exit_fail;
627627
}
628628

@@ -655,7 +655,7 @@ PHP_FUNCTION(proc_open)
655655
descriptors[ndesc].mode = DESC_FILE;
656656

657657
} else if (Z_TYPE_P(descitem) != IS_ARRAY) {
658-
php_error_docref(NULL, E_WARNING, "Descriptor item must be either an array or a File-Handle");
658+
zend_value_error("Descriptor item must be either an array or a File-Handle");
659659
goto exit_fail;
660660
} else {
661661

@@ -664,7 +664,7 @@ PHP_FUNCTION(proc_open)
664664
goto exit_fail;
665665
}
666666
} else {
667-
php_error_docref(NULL, E_WARNING, "Missing handle qualifier in array");
667+
zend_value_error("Missing handle qualifier in array");
668668
goto exit_fail;
669669
}
670670

@@ -677,7 +677,7 @@ PHP_FUNCTION(proc_open)
677677
goto exit_fail;
678678
}
679679
} else {
680-
php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'pipe'");
680+
zend_value_error("Missing mode parameter for 'pipe'");
681681
goto exit_fail;
682682
}
683683

@@ -718,7 +718,7 @@ PHP_FUNCTION(proc_open)
718718
goto exit_fail;
719719
}
720720
} else {
721-
php_error_docref(NULL, E_WARNING, "Missing file name parameter for 'file'");
721+
zend_value_error("Missing file name parameter for 'file'");
722722
goto exit_fail;
723723
}
724724

@@ -727,7 +727,7 @@ PHP_FUNCTION(proc_open)
727727
goto exit_fail;
728728
}
729729
} else {
730-
php_error_docref(NULL, E_WARNING, "Missing mode parameter for 'file'");
730+
zend_value_error("Missing mode parameter for 'file'");
731731
goto exit_fail;
732732
}
733733

@@ -760,11 +760,11 @@ PHP_FUNCTION(proc_open)
760760
php_file_descriptor_t childend;
761761

762762
if (!ztarget) {
763-
php_error_docref(NULL, E_WARNING, "Missing redirection target");
763+
zend_value_error("Missing redirection target");
764764
goto exit_fail;
765765
}
766766
if (Z_TYPE_P(ztarget) != IS_LONG) {
767-
php_error_docref(NULL, E_WARNING, "Redirection target must be an integer");
767+
zend_value_error("Redirection target must be an integer");
768768
goto exit_fail;
769769
}
770770

ext/standard/tests/general_functions/proc_open_array.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ $ds = [
1010
2 => ['pipe', 'w'],
1111
];
1212

13-
echo "Empty command array:";
14-
var_dump(proc_open([], $ds, $pipes));
13+
echo "Empty command array:\n";
14+
try {
15+
proc_open([], $ds, $pipes);
16+
} catch (ValueError $exception) {
17+
echo $exception->getMessage() . "\n";
18+
}
1519

1620
echo "\nNul byte in program name:";
1721
var_dump(proc_open(["php\0oops"], $ds, $pipes));
@@ -56,8 +60,7 @@ proc_close($proc);
5660
?>
5761
--EXPECTF--
5862
Empty command array:
59-
Warning: proc_open(): Command array must have at least one element in %s on line %d
60-
bool(false)
63+
Command array must have at least one element
6164

6265
Nul byte in program name:
6366
Warning: proc_open(): Command array element 1 contains a null byte in %s on line %d

ext/standard/tests/general_functions/proc_open_pipes3.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ $spec[$i] = array('pi');
1414
proc_open("$php -n $callee", $spec, $pipes);
1515

1616
$spec[$i] = 1;
17-
proc_open("$php -n $callee", $spec, $pipes);
17+
try {
18+
proc_open("$php -n $callee", $spec, $pipes);
19+
} catch (ValueError $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
1822

1923
$spec[$i] = array('pipe', "test");
2024
proc_open("$php -n $callee", $spec, $pipes);
@@ -28,8 +32,7 @@ echo "END\n";
2832
?>
2933
--EXPECTF--
3034
Warning: proc_open(): pi is not a valid descriptor spec/mode in %s on line %d
31-
32-
Warning: proc_open(): Descriptor item must be either an array or a File-Handle in %s on line %d
35+
Descriptor item must be either an array or a File-Handle
3336
array(4) {
3437
[3]=>
3538
resource(%d) of type (Unknown)

ext/standard/tests/general_functions/proc_open_redirect.phpt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@ Redirection support in proc_open
44
<?php
55

66
$php = getenv('TEST_PHP_EXECUTABLE');
7-
var_dump(proc_open([$php], [['redirect']], $pipes));
8-
var_dump(proc_open([$php], [['redirect', 'foo']], $pipes));
9-
var_dump(proc_open([$php], [['redirect', 42]], $pipes));
7+
try {
8+
proc_open([$php], [['redirect']], $pipes);
9+
} catch (ValueError $exception) {
10+
echo $exception->getMessage() . "\n";
11+
}
12+
13+
try {
14+
proc_open([$php], [['redirect', 'foo']], $pipes);
15+
} catch (ValueError $exception) {
16+
echo $exception->getMessage() . "\n";
17+
}
18+
19+
try {
20+
proc_open([$php], [['redirect', 42]], $pipes);
21+
} catch (ValueError $exception) {
22+
echo $exception->getMessage() . "\n";
23+
}
1024

1125
echo "\nWith pipe:\n";
1226
$cmd = [$php, '-r', 'echo "Test\n"; fprintf(STDERR, "Error");'];
@@ -38,14 +52,10 @@ proc_close($proc);
3852

3953
?>
4054
--EXPECTF--
41-
Warning: proc_open(): Missing redirection target in %s on line %d
42-
bool(false)
43-
44-
Warning: proc_open(): Redirection target must be an integer in %s on line %d
45-
bool(false)
55+
Missing redirection target
56+
Redirection target must be an integer
4657

47-
Warning: proc_open(): Redirection target 42 not found in %s on line %d
48-
bool(false)
58+
Warning: proc_open(): Redirection target 42 not found in %s
4959

5060
With pipe:
5161
array(1) {

0 commit comments

Comments
 (0)