]> granicus.if.org Git - php/commitdiff
MFH: Fixed stream_get_contents() when using $maxlength and socket is not
authorArnaud Le Blanc <lbarnaud@php.net>
Tue, 11 Nov 2008 01:56:33 +0000 (01:56 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Tue, 11 Nov 2008 01:56:33 +0000 (01:56 +0000)
closed. indeyets@php.net on #46049.

NEWS
ext/standard/tests/streams/stream_get_contents_002.phpt [new file with mode: 0644]
main/streams/streams.c

diff --git a/NEWS b/NEWS
index 93f260962011f87f40a5a3957363ee1a5316b34e..fa32b5decde12fa2e6dc4aa0588cdcbc8b97e0d9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ PHP                                                                        NEWS
 - Fixed bug #44818 (php://memory writeable when opened read only). (Arnaud)
 - Fixed bug #30312 (sybase_unbuffered_query calls). (Timm)
 
+- Fixed stream_get_contents() when using $maxlength and socket is not
+  closed. indeyets@php.net on #46049. (Arnaud)
+
 06 Nov 2008, PHP 5.2.7RC3
 - Added PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION,
   PHP_EXTRA_VERSION, PHP_VERSION_ID, PHP_ZTS and PHP_DEBUG constants. (Pierre)
diff --git a/ext/standard/tests/streams/stream_get_contents_002.phpt b/ext/standard/tests/streams/stream_get_contents_002.phpt
new file mode 100644 (file)
index 0000000..66ff3fb
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+stream_get_contents() - Testing on socket with $maxlength
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') die("skip: non windows test");
+?>
+--FILE--
+<?php
+$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+
+stream_set_timeout($sockets[1], 6000);
+
+fwrite($sockets[0], b"foo");
+var_dump(stream_get_contents($sockets[1], 3));
+
+?>
+--EXPECT--
+string(3) "foo"
index 4dd0f7442cd4d6c2cc07835b364646ce89162f3d..747aa4b9180b085da3cfbbc529b6ae25c1334b80 100755 (executable)
@@ -1234,7 +1234,7 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
 
        if (maxlen > 0) {
                ptr = *buf = pemalloc_rel_orig(maxlen + 1, persistent);
-               while ((len < maxlen) & !php_stream_eof(src)) {
+               while ((len < maxlen) && !php_stream_eof(src)) {
                        ret = php_stream_read(src, ptr, maxlen - len);
                        len += ret;
                        ptr += ret;