bug52820.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream)
  3. --SKIPIF--
  4. <?php
  5. if (!function_exists('leak_variable'))
  6. die("skip only for debug builds");
  7. /* unfortunately no standard function does a cast to FILE*, so we need
  8. * curl to test this */
  9. if (!extension_loaded("curl")) exit("skip curl extension not loaded");
  10. $handle=curl_init('http://127.0.0.1:37349/');
  11. curl_setopt($handle, CURLOPT_VERBOSE, true);
  12. curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  13. if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))
  14. die("skip fopencookie not supported on this platform");
  15. --FILE--
  16. <?php
  17. function do_stuff($url) {
  18. $handle=curl_init('http://127.0.0.1:37349/');
  19. curl_setopt($handle, CURLOPT_VERBOSE, true);
  20. curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  21. curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));
  22. curl_exec($handle);
  23. echo "About to rewind!\n";
  24. rewind($o);
  25. echo stream_get_contents($o);
  26. return $o;
  27. }
  28. echo "temp stream (close after):\n";
  29. fclose(do_stuff("php://temp"));
  30. echo "\nmemory stream (close after):\n";
  31. fclose(do_stuff("php://memory"));
  32. echo "\ntemp stream (leak):\n";
  33. leak_variable(do_stuff("php://temp"), true);
  34. echo "\nmemory stream (leak):\n";
  35. leak_variable(do_stuff("php://memory"), true);
  36. echo "\nDone.\n";
  37. --EXPECTF--
  38. temp stream (close after):
  39. About to rewind!
  40. * %ATrying 127.0.0.1...%AConnection refused%A
  41. * Closing connection%A%d
  42. memory stream (close after):
  43. About to rewind!
  44. * %ATrying 127.0.0.1...%AConnection refused%A
  45. * Closing connection%A%d
  46. temp stream (leak):
  47. About to rewind!
  48. * %ATrying 127.0.0.1...%AConnection refused%A
  49. * Closing connection%A%d
  50. memory stream (leak):
  51. About to rewind!
  52. * %ATrying 127.0.0.1...%AConnection refused%A
  53. * Closing connection%A%d
  54. Done.