bug68077.phpt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --TEST--
  2. Bug #68077 (LOAD DATA LOCAL INFILE / open_basedir restriction)
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. if (!$IS_MYSQLND) {
  8. die("skip: test applies only to mysqlnd");
  9. }
  10. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  11. die("skip Cannot connect to MySQL");
  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. open_basedir=
  19. --FILE--
  20. <?php
  21. require_once("connect.inc");
  22. ini_set("open_basedir", __DIR__);
  23. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  24. printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  25. }
  26. if (!$link->query("DROP TABLE IF EXISTS test")) {
  27. printf("[002] [%d] %s\n", $link->errno, $link->error);
  28. }
  29. if (!$link->query("CREATE TABLE test (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) {
  30. printf("[003] [%d] %s\n", $link->errno, $link->error);
  31. }
  32. if (FALSE == file_put_contents(__DIR__ . '/bug53503.data', "1\n2\n3\n"))
  33. printf("[004] Failed to create CVS file\n");
  34. if (!$link->query("SELECT 1 FROM DUAL"))
  35. printf("[005] [%d] %s\n", $link->errno, $link->error);
  36. if (!$link->query("LOAD DATA LOCAL INFILE '" . __DIR__ . "/bug53503.data' INTO TABLE test")) {
  37. printf("[006] [%d] %s\n", $link->errno, $link->error);
  38. echo "bug\n";
  39. } else {
  40. echo "done\n";
  41. }
  42. ini_set("open_basedir", __DIR__ . "/dummy");
  43. if (!$link->query("LOAD DATA LOCAL INFILE '" . __DIR__ . "/bug53503.data' INTO TABLE test")) {
  44. printf("[006] [%d] %s\n", $link->errno, $link->error);
  45. echo "done\n";
  46. } else {
  47. echo "bug\n";
  48. }
  49. $link->close();
  50. ?>
  51. --CLEAN--
  52. <?php
  53. require_once('connect.inc');
  54. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  55. printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  56. $host, $user, $db, $port, $socket);
  57. }
  58. if (!$link->query($link, 'DROP TABLE IF EXISTS test')) {
  59. printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  60. }
  61. $link->close();
  62. unlink('bug53503.data');
  63. ?>
  64. --EXPECTF--
  65. done
  66. [006] [2000] open_basedir restriction in effect. Unable to open file
  67. done