]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #43522 (stream_get_line() eats additional characters)
authorIlia Alshanetsky <iliaa@php.net>
Mon, 10 Dec 2007 14:18:02 +0000 (14:18 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 10 Dec 2007 14:18:02 +0000 (14:18 +0000)
NEWS
ext/standard/tests/file/bug43522.phpt [new file with mode: 0644]
main/streams/streams.c

diff --git a/NEWS b/NEWS
index aec5190051b8cae1895533de90bc61b96c5f8a61..00cf11231aae727270d2b1dc32bc678658f8bdf3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ PHP                                                                        NEWS
 - Fixed weired behavior in CGI parameter parsing. (Dmitry, Hannes Magnusson)
 
 - Fixed bug #43533 (escapeshellarg('') returns null). (Ilia)
+- Fixed bug #43522 (stream_get_line() eats additional characters). (Felipe,
+  Ilia)
 - Fixed bug #43495 (array_merge_recursive() crashes with recursive arrays).
   (Ilia)
 - Fixed bug #43493 (pdo_pgsql does not send username on connect when password
diff --git a/ext/standard/tests/file/bug43522.phpt b/ext/standard/tests/file/bug43522.phpt
new file mode 100644 (file)
index 0000000..10e44fc
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #43522 (stream_get_line() eats additional characters)
+--FILE--
+<?php // 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
+$fp = fopen(__FILE__, 'r'); // Open self
+
+DoTest($fp, 'ZZZ');  // test multi-char delimiter
+DoTest($fp, "Z");  // test single-char delimiter
+
+function DoTest($fp, $delim) {
+       echo "Delimiter:  " . $delim . "\n";
+       rewind($fp);
+       echo "\t" . stream_get_line($fp, 10, $delim) . "\n";
+       echo "\t" . stream_get_line($fp, 10, $delim) . "\n";
+}
+
+?>
+--EXPECT--
+Delimiter:  ZZZ
+       <?php // 1
+       234567890A
+Delimiter:  Z
+       <?php // 1
+       234567890A
index ae45653d551d5eed2a154e4b99cb0af5da321327..39780cd5a4a2715ac4fe6138849e7d3c37f26897 100755 (executable)
@@ -856,9 +856,9 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
                toread = maxlen;
        } else {
                if (delim_len == 1) {
-                       e = memchr(stream->readbuf + stream->readpos, *delim, stream->writepos - stream->readpos);
+                       e = memchr(stream->readbuf + stream->readpos, *delim, maxlen);
                } else {
-                       e = php_memnstr(stream->readbuf + stream->readpos, delim, delim_len, (stream->readbuf + stream->writepos));
+                       e = php_memnstr(stream->readbuf + stream->readpos, delim, delim_len, (stream->readbuf + stream->readpos + maxlen));
                }
 
                if (!e) {