bug54798.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Bug #54798 (Segfault when CURLOPT_STDERR file pointer is closed before calling curl_exec)
  3. --SKIPIF--
  4. <?php
  5. include 'skipif.inc';
  6. ?>
  7. --FILE--
  8. <?php
  9. function checkForClosedFilePointer($host, $curl_option, $description) {
  10. $fp = fopen(dirname(__FILE__) . '/bug54798.tmp', 'w+');
  11. $ch = curl_init();
  12. // we also need CURLOPT_VERBOSE to be set to test CURLOPT_STDERR properly
  13. if (CURLOPT_STDERR == $curl_option) {
  14. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  15. }
  16. if (CURLOPT_INFILE == $curl_option) {
  17. curl_setopt($ch, CURLOPT_UPLOAD, 1);
  18. }
  19. curl_setopt($ch, $curl_option, $fp);
  20. curl_setopt($ch, CURLOPT_URL, $host);
  21. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  22. fclose($fp); // <-- premature close of $fp caused a crash!
  23. curl_exec($ch);
  24. curl_close($ch);
  25. echo "Ok for $description\n";
  26. }
  27. $options_to_check = array(
  28. "CURLOPT_STDERR",
  29. "CURLOPT_WRITEHEADER",
  30. "CURLOPT_FILE",
  31. "CURLOPT_INFILE"
  32. );
  33. include 'server.inc';
  34. $host = curl_cli_server_start();
  35. foreach($options_to_check as $option) {
  36. checkForClosedFilePointer($host, constant($option), $option);
  37. }
  38. ?>
  39. ===DONE===
  40. --CLEAN--
  41. <?php @unlink(dirname(__FILE__) . '/bug54798.tmp'); ?>
  42. --EXPECTF--
  43. %a
  44. %aOk for CURLOPT_STDERR
  45. %aOk for CURLOPT_WRITEHEADER
  46. %aOk for CURLOPT_FILE
  47. %aOk for CURLOPT_INFILE
  48. ===DONE===