bug49442.phpt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. --TEST--
  2. Bug #49422 (mysqlnd: mysqli_real_connect() and LOAD DATA INFILE crash)
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. $link = mysqli_init();
  9. if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
  10. die(sprintf("skip Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
  11. }
  12. include_once("local_infile_tools.inc");
  13. if ($msg = check_local_infile_support($link, $engine))
  14. die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error));
  15. mysqli_close($link);
  16. ?>
  17. --INI--
  18. mysqli.allow_local_infile=1
  19. mysqli.allow_persistent=1
  20. mysqli.max_persistent=1
  21. --FILE--
  22. <?php
  23. include ("connect.inc");
  24. $link = mysqli_init();
  25. if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
  26. printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  27. }
  28. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) {
  29. printf("[002] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  30. }
  31. if (!mysqli_query($link, 'CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE=' . $engine)) {
  32. printf("[003] Failed to create test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  33. }
  34. include("local_infile_tools.inc");
  35. $file = create_standard_csv(4);
  36. if (!@mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
  37. INTO TABLE test
  38. FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
  39. LINES TERMINATED BY '\n'",
  40. mysqli_real_escape_string($link, $file)))) {
  41. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  42. }
  43. if (!$res = mysqli_query($link, "SELECT * FROM test ORDER BY id"))
  44. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  45. $rows = array();
  46. while ($row = mysqli_fetch_assoc($res)) {
  47. var_dump($row);
  48. $rows[] = $row;
  49. }
  50. mysqli_free_result($res);
  51. mysqli_query($link, "DELETE FROM test");
  52. mysqli_close($link);
  53. if ($IS_MYSQLND) {
  54. /*
  55. mysqlnd makes a connection created through mysql_init()/mysqli_real_connect() always a 'persistent' one.
  56. At this point 'persistent' is not to be confused with what a user calls a 'persistent' - in this case
  57. 'persistent' means that mysqlnd uses malloc() instead of emalloc(). nothing else. ext/mysqli will
  58. not consider it as a 'persistent' connection in a user sense, ext/mysqli will not apply max_persistent etc.
  59. Its only about malloc() vs. emalloc().
  60. However, the bug is about malloc() and efree(). You can make make mysqlnd use malloc() by either using
  61. pconnect or mysql_init() - so we should test pconnect as well..
  62. */
  63. $host = 'p:' . $host;
  64. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  65. printf("[007] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  66. }
  67. /* bug happened during query processing */
  68. if (!@mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s'
  69. INTO TABLE test
  70. FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
  71. LINES TERMINATED BY '\n'",
  72. mysqli_real_escape_string($link, $file)))) {
  73. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  74. }
  75. /* we survived? that's good enough... */
  76. if (!$res = mysqli_query($link, "SELECT * FROM test ORDER BY id"))
  77. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  78. $i = 0;
  79. while ($row = mysqli_fetch_assoc($res)) {
  80. if (($row['id'] != $rows[$i]['id']) || ($row['label'] != $rows[$i]['label'])) {
  81. printf("[010] Wrong values, check manually!\n");
  82. }
  83. $i++;
  84. }
  85. mysqli_close($link);
  86. }
  87. print "done!";
  88. ?>
  89. --CLEAN--
  90. <?php
  91. require_once("clean_table.inc");
  92. ?>
  93. --EXPECT--
  94. array(2) {
  95. ["id"]=>
  96. string(2) "97"
  97. ["label"]=>
  98. string(1) "x"
  99. }
  100. array(2) {
  101. ["id"]=>
  102. string(2) "98"
  103. ["label"]=>
  104. string(1) "y"
  105. }
  106. array(2) {
  107. ["id"]=>
  108. string(2) "99"
  109. ["label"]=>
  110. string(1) "z"
  111. }
  112. done!