]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #30362 (stream_get_line() not handling end string correctly)
authorIlia Alshanetsky <iliaa@php.net>
Mon, 11 Oct 2004 18:33:00 +0000 (18:33 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 11 Oct 2004 18:33:00 +0000 (18:33 +0000)
NEWS
ext/standard/streamsfuncs.c
main/streams/streams.c

diff --git a/NEWS b/NEWS
index 1bc542cbe3d68268552e1524b6824846e9759fee..35ca64524253e06811ac88290c3ecfd3dc19f205 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP                                                                        NEWS
   (vnegrier at esds dot com, Wez).
 - Fixed potential problems with unserializing invalid serialize data. (Marcus)
 - Fixed bug #30375 (cal_info() does not work without a parameter). (Ilia)
+- Fixed bug #30362 (stream_get_line() not handling end string correctly).
+  (Ilia)
 - Fixed bug #30356 (str_ireplace() does not work on all strings). (Ilia)
 - Fixed bug #30344 (Reflection::getModifierNames() returns too long strings).
   (Marcus)
index 272cd26d6c5c9a6d689283912219ed41ba1ad395..520cab7b94793cb7ee84df31184242d866f9e543 100644 (file)
@@ -1059,11 +1059,11 @@ PHP_FUNCTION(stream_filter_append)
 
 /* }}} */
 
-/* {{{ proto string stream_get_line(resource stream, int maxlen, string ending)
+/* {{{ proto string stream_get_line(resource stream, int maxlen [, string ending])
    Read up to maxlen bytes from a stream or until the ending string is found */
 PHP_FUNCTION(stream_get_line)
 {
-       char *str;
+       char *str = NULL;
        int str_len;
        long max_length;
        zval *zstream;
@@ -1071,7 +1071,7 @@ PHP_FUNCTION(stream_get_line)
        size_t buf_size;
        php_stream *stream;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &zstream, &max_length, &str, &str_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|s", &zstream, &max_length, &str, &str_len) == FAILURE) {
                RETURN_FALSE;
        }
 
index a0757d38116fb4cf495342024391ab959dee3d66..a8f010605b887b4d69c758ab8ee7fc64ab8803b8 100755 (executable)
@@ -835,7 +835,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
 
        php_stream_fill_read_buffer(stream, maxlen TSRMLS_CC);
 
-       if (delim_len == 0) {
+       if (delim_len == 0 || !delim) {
                toread = maxlen;
        } else {
                if (delim_len == 1) {
@@ -859,6 +859,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
        *returned_len = php_stream_read(stream, buf, toread);
                        
        if (*returned_len >= 0) {
+               buf[*returned_len] = '\0';
                return buf;
        } else {
                efree(buf);