bug_41125.phpt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --TEST--
  2. Bug #41125 (PDO mysql + quote() + prepare() can result in segfault)
  3. --EXTENSIONS--
  4. pdo_mysql
  5. --SKIPIF--
  6. <?php
  7. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  8. MySQLPDOTest::skip();
  9. $db = MySQLPDOTest::factory();
  10. $row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
  11. $matches = array();
  12. if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
  13. die(sprintf("skip Cannot determine MySQL Server version\n"));
  14. $version = $matches[1] * 10000 + $matches[2] * 100 + $matches[3];
  15. if ($version < 40100)
  16. die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n",
  17. $matches[1], $matches[2], $matches[3], $version));
  18. ?>
  19. --FILE--
  20. <?php
  21. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  22. $db = MySQLPDOTest::factory();
  23. $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
  24. $db->exec("DROP TABLE IF EXISTS test");
  25. // And now allow the evil to do his work
  26. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
  27. $sql = "CREATE TABLE IF NOT EXISTS test(id INT); INSERT INTO test(id) VALUES (1); SELECT * FROM test; INSERT INTO test(id) VALUES (2); SELECT * FROM test;";
  28. $stmt = $db->query($sql);
  29. do {
  30. var_dump($stmt->fetchAll());
  31. } while ($stmt->nextRowset());
  32. print "done!";
  33. ?>
  34. --CLEAN--
  35. <?php
  36. require __DIR__ . '/mysql_pdo_test.inc';
  37. $db = MySQLPDOTest::factory();
  38. $db->exec("DROP TABLE IF EXISTS test");
  39. ?>
  40. --EXPECT--
  41. array(0) {
  42. }
  43. array(0) {
  44. }
  45. array(1) {
  46. [0]=>
  47. array(2) {
  48. ["id"]=>
  49. string(1) "1"
  50. [0]=>
  51. string(1) "1"
  52. }
  53. }
  54. array(0) {
  55. }
  56. array(2) {
  57. [0]=>
  58. array(2) {
  59. ["id"]=>
  60. string(1) "1"
  61. [0]=>
  62. string(1) "1"
  63. }
  64. [1]=>
  65. array(2) {
  66. ["id"]=>
  67. string(1) "2"
  68. [0]=>
  69. string(1) "2"
  70. }
  71. }
  72. done!