tony2001                Mon May 29 10:23:53 2006 UTC

  Modified files:              
    /php-src/ext/standard       file.c 
  Log:
  prevent resource leaking when passing invalid stream resource as second 
argument
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/file.c?r1=1.442&r2=1.443&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.442 php-src/ext/standard/file.c:1.443
--- php-src/ext/standard/file.c:1.442   Fri May 19 10:44:34 2006
+++ php-src/ext/standard/file.c Mon May 29 10:23:53 2006
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.442 2006/05/19 10:44:34 hholzgra Exp $ */
+/* $Id: file.c,v 1.443 2006/05/29 10:23:53 tony2001 Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -588,12 +588,17 @@
        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 @@
 
        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;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to