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

index 5b7a2bf209f0579b7469580e2e17d1ca22af1f14..91093a76534399d53a70ba075d40fb6268fca26d 100644 (file)
@@ -1117,11 +1117,11 @@ PHP_FUNCTION(stream_filter_remove)
 }
 /* }}} */
 
-/* {{{ 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;
@@ -1129,7 +1129,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 6242afcf82773cddb0e8f131cd0150fb8fa410bb..9a071746bc602aea439ad1ecd6d1f2ffa34f77ab 100755 (executable)
@@ -846,7 +846,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) {
@@ -870,6 +870,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);