Skip to content

Commit 1b01bf3

Browse files
committed
Add missing error condition to stream_context_set_option()
Previously this caused a null pointer dereference if the value argument was not provided.
1 parent 6617829 commit 1b01bf3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

ext/standard/streamsfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,10 @@ PHP_FUNCTION(stream_context_set_option)
10191019
zend_argument_value_error(3, "cannot be null when argument #2 ($wrapper_or_options) is a string");
10201020
RETURN_THROWS();
10211021
}
1022+
if (!zvalue) {
1023+
zend_argument_value_error(4, "must be provided when argument #2 ($wrapper_or_options) is a string");
1024+
RETURN_THROWS();
1025+
}
10221026

10231027
RETURN_BOOL(php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue) == SUCCESS);
10241028
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
stream_context_set_option() error conditions
3+
--FILE--
4+
<?php
5+
6+
$ctx = stream_context_create();
7+
try {
8+
stream_context_set_option($ctx, [], "x");
9+
} catch (Error $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
try {
13+
stream_context_set_option($ctx, [], null, "x");
14+
} catch (Error $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
try {
18+
stream_context_set_option($ctx, "x");
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
try {
23+
stream_context_set_option($ctx, "x", "y");
24+
} catch (Error $e) {
25+
echo $e->getMessage(), "\n";
26+
}
27+
28+
?>
29+
--EXPECT--
30+
stream_context_set_option(): Argument #3 ($option_name) must be null when argument #2 ($wrapper_or_options) is an array
31+
stream_context_set_option(): Argument #4 ($value) cannot be provided when argument #2 ($wrapper_or_options) is an array
32+
stream_context_set_option(): Argument #3 ($option_name) cannot be null when argument #2 ($wrapper_or_options) is a string
33+
stream_context_set_option(): Argument #4 ($value) must be provided when argument #2 ($wrapper_or_options) is a string

0 commit comments

Comments
 (0)