Skip to content

Commit 89a5bd6

Browse files
committed
Fixed bug #74090 stream_get_contents maxlength>-1 returns empty string
1 parent 3917350 commit 89a5bd6

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #74090 stream_get_contents maxlength>-1 returns empty string on windows
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_ONLINE_TESTS")) { die('skip: online test'); }
6+
if (getenv("SKIP_SLOW_TESTS")) { die('skip: slow test'); }
7+
?>
8+
--FILE--
9+
<?php
10+
$data = base64_decode("1oIBAAABAAAAAAAAB2V4YW1wbGUDb3JnAAABAAE=");
11+
$fd = stream_socket_client("udp://8.8.8.8:53", $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
12+
stream_set_blocking($fd, 0);
13+
stream_socket_sendto($fd,$data);
14+
sleep(1);
15+
$ret = stream_get_contents($fd,65565);
16+
var_dump(strlen($ret) > 0);
17+
stream_socket_shutdown($fd,STREAM_SHUT_RDWR);
18+
?>
19+
==DONE==
20+
--EXPECTF--
21+
bool(true)
22+
==DONE==

‎main/streams/php_streams_int.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
# undef EWOULDBLOCK
5454
# endif
5555
# define EWOULDBLOCK WSAEWOULDBLOCK
56+
# ifdef EMSGSIZE
57+
# undef EMSGSIZE
58+
# endif
59+
# define EMSGSIZE WSAEMSGSIZE
5660
#endif
5761

5862
/* This functions transforms the first char to 'w' if it's not 'r', 'a' or 'w'

‎main/streams/xp_socket.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
336336
ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK);
337337
err = php_socket_errno();
338338
if (0 == ret || /* the counterpart did properly shutdown*/
339-
(0 > ret && err != EWOULDBLOCK && err != EAGAIN)) { /* there was an unrecoverable error */
339+
(0 > ret && err != EWOULDBLOCK && err != EAGAIN && err != EMSGSIZE)) { /* there was an unrecoverable error */
340340
alive = 0;
341341
}
342342
}

0 commit comments

Comments
 (0)