summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Dovgal <tony2001@php.net>2006-05-29 10:24:49 +0000
committerAntony Dovgal <tony2001@php.net>2006-05-29 10:24:49 +0000
commit1a63feffd1fc85cd063e76a46edf8bbb6403ddfe (patch)
tree3245e86d72acdadbd5784428e57df925056bc453
parent10ed7a1e0ac0cd502f6ff33181cb57d83fa1f2d7 (diff)
downloadphp-git-1a63feffd1fc85cd063e76a46edf8bbb6403ddfe.tar.gz
MFH: prevent resource leaking when passing invalid stream resource as second argument
-rw-r--r--ext/standard/file.c11
1 files changed, 5 insertions, 6 deletions
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: