]> granicus.if.org Git - php/commitdiff
MFH: prevent resource leaking when passing invalid stream resource as second argument
authorAntony Dovgal <tony2001@php.net>
Mon, 29 May 2006 10:24:49 +0000 (10:24 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 29 May 2006 10:24:49 +0000 (10:24 +0000)
ext/standard/file.c

index f43225e961b935b1c1c677828bb096faa14503b7..e97797deb79e6aa6c6642eaf281fc5d730fbbee1 100644 (file)
@@ -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: