Skip to content

Commit 332b067

Browse files
committed
Fix GH-15937: stream timeout option overflow.
close GH-15942
1 parent f564955 commit 332b067

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ PHP NEWS
4343
- Standard:
4444
. Fixed bug GH-15613 (overflow on unpack call hex string repeater).
4545
(David Carlier)
46+
. Fixed bug GH-15937 (overflow on stream timeout option value).
47+
(David Carlier)
4648

4749
- Streams:
4850
. Fixed bugs GH-15908 and GH-15026 (leak / assertion failure in streams.c).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-15937 (stream overflow on timeout setting)
3+
--SKIPIF--
4+
<?php if (getenv("SKIP_ONLINE_TESTS")) die("skip online test"); ?>
5+
--FILE--
6+
<?php
7+
$config = [
8+
'http' => [
9+
'timeout' => PHP_INT_MAX,
10+
],
11+
];
12+
$ctx = stream_context_create($config);
13+
var_dump(fopen("http://www.example.com", "r", false, $ctx));
14+
?>
15+
--EXPECTF--
16+
resource(%d) of type (stream)

main/php_network.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ PHPAPI int php_poll2(php_pollfd *ufds, unsigned int nfds, int timeout);
162162
/* timeval-to-timeout (for poll(2)) */
163163
static inline int php_tvtoto(struct timeval *timeouttv)
164164
{
165-
if (timeouttv) {
165+
if (timeouttv && timeouttv->tv_sec >= 0 && timeouttv->tv_sec <= ((INT_MAX - 1000) / 1000)) {
166166
return (timeouttv->tv_sec * 1000) + (timeouttv->tv_usec / 1000);
167167
}
168168
return -1;

0 commit comments

Comments
 (0)