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

index 121ba395ad55c9025cadf65e58bc4e0202503517..551605f871544ee3994204e02d5b9beb7fceaf6f 100644 (file)
@@ -588,12 +588,17 @@ PHP_FUNCTION(file_put_contents)
        zval *zcontext = NULL;
        php_stream_context *context = NULL;
        char mode[3] = { 'w', 0, 0 };
+       php_stream *srcstream;
        
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tz/|lr!", &filename, &filename_len, &filename_type,
                                &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);
 
        if (flags & PHP_FILE_APPEND) {
@@ -627,14 +632,8 @@ PHP_FUNCTION(file_put_contents)
 
        switch (Z_TYPE_P(data)) {
                case IS_RESOURCE:
-               {
-                       php_stream *srcstream;
-                       php_stream_from_zval(srcstream, &data);
-
                        numchars = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL);
-
                        break;
-               }
                case IS_ARRAY:
                        if (zend_hash_num_elements(Z_ARRVAL_P(data))) {
                                zval **tmp;