felipe          Thu Oct 30 15:53:18 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/streams stream_get_contents_001.phpt 

  Modified files:              
    /php-src/ext/standard       streamsfuncs.c 
  Log:
  - Fixed memory leak when using offset out of range. (php_stream_copy_to_mem 
returns 0, but the empty string is alloced)
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.58.2.6.2.15.2.26&r2=1.58.2.6.2.15.2.27&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.26 
php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.27
--- php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.26      Thu Oct 30 
14:34:25 2008
+++ php-src/ext/standard/streamsfuncs.c Thu Oct 30 15:53:18 2008
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.c,v 1.58.2.6.2.15.2.26 2008/10/30 14:34:25 felipe Exp $ */
+/* $Id: streamsfuncs.c,v 1.58.2.6.2.15.2.27 2008/10/30 15:53:18 felipe Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -416,18 +416,16 @@
                RETURN_FALSE;
        }
 
-       if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
-               
-               if (PG(magic_quotes_runtime)) {
+       len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);
+       
+       if (contents) {
+               if (len && PG(magic_quotes_runtime)) {
                        contents = php_addslashes(contents, len, &newlen, 1 
TSRMLS_CC); /* 1 = free source string */
                        len = newlen;
                }
-
                RETVAL_STRINGL(contents, len, 0);
-       } else if (len == 0) {
-               RETVAL_EMPTY_STRING();
        } else {
-               RETVAL_FALSE;
+               RETVAL_EMPTY_STRING();
        }
 }
 /* }}} */

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/streams/stream_get_contents_001.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/streams/stream_get_contents_001.phpt
+++ php-src/ext/standard/tests/streams/stream_get_contents_001.phpt
--TEST--
stream_get_contents() - Testing offset out of range
--FILE--
<?php

$tmp = tmpfile();

fwrite($tmp, "12345");

echo stream_get_contents($tmp, 2, 5), "--\n";
echo stream_get_contents($tmp, 2), "--\n";
echo stream_get_contents($tmp, 2, 3), "--\n";
echo stream_get_contents($tmp, 2, -1), "--\n";

@unlink($tmp);

?>
--EXPECT--
--
--
45--
--



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

Reply via email to