From: Antony Dovgal Date: Mon, 29 May 2006 10:24:49 +0000 (+0000) Subject: MFH: prevent resource leaking when passing invalid stream resource as second argument X-Git-Tag: php-5.2.0RC1~443 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a63feffd1fc85cd063e76a46edf8bbb6403ddfe;p=php MFH: prevent resource leaking when passing invalid stream resource as second argument --- diff --git a/ext/standard/file.c b/ext/standard/file.c index f43225e961..e97797deb7 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -571,12 +571,17 @@ PHP_FUNCTION(file_put_contents) long flags = 0; zval *zcontext = NULL; php_stream_context *context = NULL; + php_stream *srcstream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { return; } + if (Z_TYPE_P(data) == IS_RESOURCE) { + php_stream_from_zval(srcstream, &data); + } + context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb", @@ -591,14 +596,8 @@ PHP_FUNCTION(file_put_contents) switch (Z_TYPE_P(data)) { case IS_RESOURCE: - { - php_stream *srcstream; - php_stream_from_zval(srcstream, &data); - numbytes = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL); - break; - } case IS_NULL: case IS_LONG: case IS_DOUBLE: