Skip to content

Commit fc3ac34

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents e8bb0a8 + 301b8e2 commit fc3ac34

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ PHP NEWS
1919
- Streams:
2020
. Fixed bug GH-17037 (UAF in user filter when adding existing filter name due
2121
to incorrect error handling). (nielsdos)
22+
. Fixed bug GH-16810 (overflow on fopen HTTP wrapper timeout value).
23+
(David Carlier)
2224

2325
- Windows:
2426
. Hardened proc_open() against cmd.exe hijacking. (cmb)

ext/standard/http_fopen_wrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
244244

245245
if (context && (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "timeout")) != NULL) {
246246
double d = zval_get_double(tmpzval);
247+
#ifndef PHP_WIN32
248+
const double timeoutmax = (double) PHP_TIMEOUT_ULL_MAX / 1000000.0;
249+
#else
250+
const double timeoutmax = (double) LONG_MAX / 1000000.0;
251+
#endif
252+
253+
if (d > timeoutmax) {
254+
php_stream_wrapper_log_error(wrapper, options, "timeout must be lower than " ZEND_ULONG_FMT, (zend_ulong)timeoutmax);
255+
zend_string_release(transport_string);
256+
php_url_free(resource);
257+
return NULL;
258+
}
247259
#ifndef PHP_WIN32
248260
timeout.tv_sec = (time_t) d;
249261
timeout.tv_usec = (size_t) ((d - timeout.tv_sec) * 1000000);

ext/standard/tests/http/gh16810.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #79265 variation: "host:" not at start of header
3+
--INI--
4+
allow_url_fopen=1
5+
--SKIPIF--
6+
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
7+
--FILE--
8+
<?php
9+
$uri = "http://www.example.com";
10+
$config = [
11+
'http' => [
12+
'timeout' => PHP_INT_MIN,
13+
],
14+
];
15+
$ctx = stream_context_create($config);
16+
var_dump(fopen($uri, "r", false, $ctx));
17+
18+
$config['http']['timeout'] = PHP_INT_MAX;
19+
$ctx = stream_context_create($config);
20+
var_dump(fopen($uri, "r", false, $ctx));
21+
?>
22+
--EXPECTF--
23+
resource(%d) of type (stream)
24+
25+
Warning: fopen(http://www.example.com): Failed to open stream: timeout must be lower than %d in %s on line %d
26+
bool(false)

0 commit comments

Comments
 (0)