bug54798.phpt 1.3 KB

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