Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed Bug #61961 (file_get_content leaks when access empty file with …

…max length)
  • Loading branch information...
commit 3e9923dd8d08f88740f58e54386c0f7c569a5aa6 1 parent 0956c00
Reeze Xia reeze authored
14 ext/standard/tests/file/bug61961.phpt
... ... @@ -0,0 +1,14 @@
  1 +--TEST--
  2 +Bug #61961 (file_get_content leaks when access empty file with max length)
  3 +--FILE--
  4 +<?php
  5 +$tmp_empty_file = __FILE__ . ".tmp";
  6 +file_put_contents($tmp_empty_file, "");
  7 +
  8 +var_dump(file_get_contents($tmp_empty_file, NULL, NULL, NULL, 10));
  9 +unlink($tmp_empty_file);
  10 +?>
  11 +==DONE==
  12 +--EXPECT--
  13 +string(0) ""
  14 +==DONE==
7 main/streams/streams.c
@@ -1366,7 +1366,12 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
1366 1366 len += ret;
1367 1367 ptr += ret;
1368 1368 }
1369   - *ptr = '\0';
  1369 + if (len) {
  1370 + *ptr = '\0';
  1371 + } else {
  1372 + pefree(*buf, persistent);
  1373 + *buf = NULL;
  1374 + }
1370 1375 return len;
1371 1376 }
1372 1377

0 comments on commit 3e9923d

Please sign in to comment.
Something went wrong with that request. Please try again.