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