com php-src: Fixed bug #71245 (file_get_contents() ignores "header" context option if it's a r eference): NEWS ext/standard/streamsfuncs.c ext/sta
ndard/tests/streams/bug71245.phpt
| From: | Xinchen Hui | Date: | Wed, 30 Dec 2015 13:04:21 +0000 |
| Subject: | com php-src: Fixed bug #71245 (file_get_contents() ignores "header" context option if it's a r eference): NEWS ext/standard/streamsfuncs.c ext/sta ndard/tests/streams/bug71245.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90478@lists.php.net to get a copy of this message | ||
Commit: 90d2f509e2164b60fc7bc8407e63504c910cce11
Author: Xinchen Hui <laruence@gmail.com> Wed, 30 Dec 2015 05:04:21 -0800
Parents: 3f07a256f75a55eaf7e7bfed681f8dfb4b901e55
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=90d2f509e2164b60fc7bc8407e63504c910cce11
Log:
Fixed bug #71245 (file_get_contents() ignores "header" context option if it's a
reference)
Bugs:
https://bugs.php.net/71245
Changed paths:
M NEWS
M ext/standard/streamsfuncs.c
A ext/standard/tests/streams/bug71245.phpt
Diff:
diff --git a/NEWS b/NEWS
index 5999518..372f47c 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ PHP NEWS
immediately). (Laruence)
- Standard:
+ . Fixed bug #71245 (file_get_contents() ignores "header" context option if
+ it's a reference). (Laruence)
. Fixed bug #71220 (Null pointer deref (segfault) in compact via ob_start).
(hugh at allthethings dot co dot nz)
. Fixed bug #71190 (substr_replace converts integers in original $search
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index f257ef8..bc8c855 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -881,10 +881,11 @@ static int parse_context_options(php_stream_context *context, zval *options)
int ret = SUCCESS;
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), wkey, wval) {
- if (wkey && Z_TYPE_P(wval) == IS_ARRAY) {
-
+ ZVAL_DEREF(wval);
+ if (Z_TYPE_P(wval) == IS_ARRAY) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) {
if (okey) {
+ ZVAL_DEREF(oval);
php_stream_context_set_option(context, ZSTR_VAL(wkey), ZSTR_VAL(okey), oval);
}
} ZEND_HASH_FOREACH_END();
diff --git a/ext/standard/tests/streams/bug71245.phpt b/ext/standard/tests/streams/bug71245.phpt
new file mode 100644
index 0000000..e1d82f6
--- /dev/null
+++ b/ext/standard/tests/streams/bug71245.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Bug #71245 (file_get_contents() ignores "header" context option if it's a reference)
+--FILE--
+<?php
+$headers = ['Host: okey.com'];
+$httpContext = [
+ 'http' => [
+ 'protocol_version' => '1.1',
+ 'method' => 'GET',
+ 'header' => &$headers,
+ 'follow_location' => 0,
+ 'max_redirects' => 0,
+ 'ignore_errors' => true,
+ 'timeout' => 60,
+ ],
+];
+$context = stream_context_create($httpContext);
+$headers = ["Host: bad.com"];
+print_r(stream_context_get_options($context));
+?>
+--EXPECTF--
+Array
+(
+ [http] => Array
+ (
+ [protocol_version] => 1.1
+ [method] => GET
+ [header] => Array
+ (
+ [0] => Host: okey.com
+ )
+
+ [follow_location] => 0
+ [max_redirects] => 0
+ [ignore_errors] => 1
+ [timeout] => 60
+ )
+
+)