com php-src: Fixed bug #74090 stream_get_contents maxleng th>-1 returns empty string: ext/standard/tests/st reams/bug74090.phpt main/streams/php_streams_ int.h main/streams/xp_socket.c

[email protected] (Anatol Belski)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    89a5bd67500510f30a729ff97048fa230c9f9bd3
Author:    Anatol Belski <[email protected]>         Wed, 15 Feb 2017 11:22:47 +0100
Parents:   391735053181f3d166e4ebb58cf04a8acf3d1724
Branches:  PHP-7.0 PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=89a5bd67500510f30a729ff97048fa230c9f9bd3

Log:
Fixed bug #74090 stream_get_contents maxlength>-1 returns empty string

Bugs:
https://bugs.php.net/74090

Changed paths:
  A  ext/standard/tests/streams/bug74090.phpt
  M  main/streams/php_streams_int.h
  M  main/streams/xp_socket.c


Diff:
diff --git a/ext/standard/tests/streams/bug74090.phpt b/ext/standard/tests/streams/bug74090.phpt
new file mode 100644
index 0000000..370dd13
--- /dev/null
+++ b/ext/standard/tests/streams/bug74090.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #74090 stream_get_contents maxlength>-1 returns empty string on windows
+--SKIPIF--
+<?php
+if (getenv("SKIP_ONLINE_TESTS")) { die('skip: online test'); }
+if (getenv("SKIP_SLOW_TESTS")) { die('skip: slow test'); }
+?>
+--FILE--
+<?php
+$data = base64_decode("1oIBAAABAAAAAAAAB2V4YW1wbGUDb3JnAAABAAE=");
+$fd = stream_socket_client("udp://8.8.8.8:53", $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
+stream_set_blocking($fd, 0);
+stream_socket_sendto($fd,$data);
+sleep(1);
+$ret = stream_get_contents($fd,65565);
+var_dump(strlen($ret) > 0);
+stream_socket_shutdown($fd,STREAM_SHUT_RDWR);
+?>
+==DONE==
+--EXPECTF--
+bool(true)
+==DONE==
diff --git a/main/streams/php_streams_int.h b/main/streams/php_streams_int.h
index 42fdfcb..13a8178 100644
--- a/main/streams/php_streams_int.h
+++ b/main/streams/php_streams_int.h
@@ -53,6 +53,10 @@
 #  undef EWOULDBLOCK
 # endif
 # define EWOULDBLOCK WSAEWOULDBLOCK
+# ifdef EMSGSIZE
+#  undef EMSGSIZE
+# endif
+# define EMSGSIZE WSAEMSGSIZE
 #endif
 
 /* This functions transforms the first char to 'w' if it's not 'r', 'a' or 'w'
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index a791621..701a993 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -336,7 +336,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
 					ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK);
 					err = php_socket_errno();
 					if (0 == ret || /* the counterpart did properly shutdown*/
-						(0 > ret && err != EWOULDBLOCK && err != EAGAIN)) { /* there was an unrecoverable error */
+						(0 > ret && err != EWOULDBLOCK && err != EAGAIN && err != EMSGSIZE)) { /* there was an unrecoverable error */
 						alive = 0;
 					}
 				}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.