Permalink
Browse files

Fixed bug in new stream_get_line() when using NUL as a delimiter.

This is the issue Derick spotted a few days ago..
  • Loading branch information...
1 parent 9ad0b87 commit a4e6394a06fb11f80426e94874d0702cf5235726 @cataphract cataphract committed with johannes Apr 7, 2012
Showing with 29 additions and 2 deletions.
  1. +27 −0 ext/standard/tests/streams/stream_get_line_NUL_delimiter.phpt
  2. +2 −2 main/streams/streams.c
@@ -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"
View
@@ -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;

0 comments on commit a4e6394

Please sign in to comment.