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