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