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