bug54798-unix.phpt 1.3 KB

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