Skip to content

Commit 0f180a6

Browse files
committed
Fixed bug in new stream_get_line() when using NUL as a delimiter.
This is the issue Derick spotted a few days ago..
1 parent 9bf8cd4 commit 0f180a6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #60455: stream_get_line and \0 as a delimiter
3+
--FILE--
4+
<?php
5+
class TestStream {
6+
private $s = 0;
7+
function stream_open($path, $mode, $options, &$opened_path) {
8+
return true;
9+
}
10+
function stream_read($count) {
11+
if ($this->s++ == 0)
12+
return "a\0";
13+
14+
return "";
15+
}
16+
function stream_eof() {
17+
return $this->s >= 2;
18+
}
19+
20+
}
21+
22+
stream_wrapper_register("test", "TestStream");
23+
24+
$f = fopen("test://", "r");
25+
var_dump(stream_get_line($f, 100, "\0"));
26+
--EXPECT--
27+
string(1) "a"

main/streams/streams.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,8 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
957957
char *ret_buf, /* returned buffer */
958958
*found_delim = NULL;
959959
size_t buffered_len,
960-
tent_ret_len; /* tentative returned length*/
961-
int has_delim = delim_len > 0 && delim[0] != '\0';
960+
tent_ret_len; /* tentative returned length */
961+
int has_delim = delim_len > 0;
962962

963963
if (maxlen == 0) {
964964
return NULL;

0 commit comments

Comments
 (0)