summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo André dos Santos Lopes <cataphract@php.net>2012-04-07 15:32:19 (GMT)
committerGustavo André dos Santos Lopes <cataphract@php.net>2012-04-07 15:32:19 (GMT)
commit0f180a63ebb2d65bbe49b68d2430639b20443e9a (patch)
tree847b20838d4b848b48424e6e955c753d6bd340e6
parent9bf8cd4b3437f6335e20843c9e3668b44761feba (diff)
downloadphp-0f180a63ebb2d65bbe49b68d2430639b20443e9a.tar.gz
Fixed bug in new stream_get_line() when using NUL as a delimiter.
This is the issue Derick spotted a few days ago..
-rw-r--r--ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt27
-rwxr-xr-xmain/streams/streams.c4
2 files changed, 29 insertions, 2 deletions
diff --git a/ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt b/ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt
new file mode 100644
index 0000000..32756d7
--- /dev/null
+++ b/ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Bug #60455: stream_get_line and \0 as a delimiter
+--FILE--
+<?php
+class TestStream {
+ private $s = 0;
+ function stream_open($path, $mode, $options, &$opened_path) {
+ return true;
+ }
+ function stream_read($count) {
+ if ($this->s++ == 0)
+ return "a\0";
+
+ return "";
+ }
+ function stream_eof() {
+ return $this->s >= 2;
+ }
+
+}
+
+stream_wrapper_register("test", "TestStream");
+
+$f = fopen("test://", "r");
+var_dump(stream_get_line($f, 100, "\0"));
+--EXPECT--
+string(1) "a"
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 639ea07..116c0aa 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -957,8 +957,8 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
char *ret_buf, /* returned buffer */
*found_delim = NULL;
size_t buffered_len,
- tent_ret_len; /* tentative returned length*/
- int has_delim = delim_len > 0 && delim[0] != '\0';
+ tent_ret_len; /* tentative returned length */
+ int has_delim = delim_len > 0;
if (maxlen == 0) {
return NULL;