]> granicus.if.org Git - php/commitdiff
- MFB: Fixed memory leak when using offset out of range. (php_stream_copy_to_mem...
authorFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 15:56:23 +0000 (15:56 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 15:56:23 +0000 (15:56 +0000)
ext/standard/streamsfuncs.c
ext/standard/tests/streams/stream_get_contents_001.phpt [new file with mode: 0644]

index d84cfc538ca35f98e6e9fc03a54f0409111f11d4..2c6acf341010862395917640b6d11fea4050966d 100644 (file)
@@ -411,18 +411,16 @@ PHP_FUNCTION(stream_get_contents)
                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();
        }
 }
 /* }}} */
diff --git a/ext/standard/tests/streams/stream_get_contents_001.phpt b/ext/standard/tests/streams/stream_get_contents_001.phpt
new file mode 100644 (file)
index 0000000..dc7fcb2
--- /dev/null
@@ -0,0 +1,22 @@
+--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--
+--