From: Antony Dovgal Date: Thu, 6 Apr 2006 19:01:56 +0000 (+0000) Subject: fix #36981 (SplFileObject->fgets() ignores max_length) X-Git-Tag: php-5.1.3RC3~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad7768ee63d8273d58f0d81222f38a0aa4c1236b;p=php fix #36981 (SplFileObject->fgets() ignores max_length) --- diff --git a/NEWS b/NEWS index bb7dadcd7f..b6ebcf73e0 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ PHP NEWS - Removed the E_STRICT deprecation notice from "var". (Ilia) - Fixed debug_zval_dump() to support private and protected members. (Dmitry) - Fixed SoapFault::getMessage(). (Dmitry) +- Fixed bug #36981 (SplFileObject->fgets() ignores max_length). (Tony) - Fixed bug #36957 (serialize() does not handle recursion). (Ilia) - Fixed bug #36944 (strncmp & strncasecmp do not return false on negative string length). (Tony) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 4fb7533b2a..6d5cb2250a 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1327,7 +1327,7 @@ static zend_function_entry spl_RecursiveDirectoryIterator_functions[] = { static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */ { char *buf; - size_t line_len; + size_t line_len = 0; int len; long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0; @@ -1340,7 +1340,17 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS return FAILURE; } - buf = php_stream_get_line(intern->u.file.stream, NULL, intern->u.file.max_line_len, &line_len); + if (intern->u.file.max_line_len > 0) { + buf = emalloc((intern->u.file.max_line_len + 1) * sizeof(char)); + if (php_stream_get_line(intern->u.file.stream, buf, intern->u.file.max_line_len, &line_len) == NULL) { + efree(buf); + buf = NULL; + } else { + buf[line_len] = '\0'; + } + } else { + buf = php_stream_get_line(intern->u.file.stream, NULL, 0, &line_len); + } if (!buf) { intern->u.file.current_line = estrdup("");