Skip to content

Commit 96404eb

Browse files
SjonHortensiusnikic
authored andcommitted
Fix #77956 - When mysqli.allow_local_infile = Off, return a client error
1 parent 62fe6ba commit 96404eb

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug #78025 (segfault when accessing properties of DOMDocumentType).
1111
(cmb)
1212

13+
- MySQLi:
14+
. Fixed bug #77956 (When mysqli.allow_local_infile = Off, use a meaningful
15+
error message). (Sjon Hortensius)
16+
1317
30 May 2019, PHP 7.2.19
1418

1519
- FPM:

ext/mysqli/tests/bug77956.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
ensure an error is returned when mysqli.allow_local_infile is off
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
?>
8+
--INI--
9+
mysqli.allow_local_infile=0
10+
--FILE--
11+
<?php
12+
require_once("connect.inc");
13+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
14+
printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
15+
}
16+
if (!$link->query("DROP TABLE IF EXISTS test")) {
17+
printf("[002] [%d] %s\n", $link->errno, $link->error);
18+
}
19+
if (!$link->query("CREATE TABLE test (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine)) {
20+
printf("[003] [%d] %s\n", $link->errno, $link->error);
21+
}
22+
if (FALSE == file_put_contents('bug77956.data', "waa? meukee!"))
23+
printf("[004] Failed to create CVS file\n");
24+
if (!$link->query("SELECT 1 FROM DUAL"))
25+
printf("[005] [%d] %s\n", $link->errno, $link->error);
26+
if (!$link->query("LOAD DATA LOCAL INFILE 'bug77956.data' INTO TABLE test")) {
27+
printf("[006] [%d] %s\n", $link->errno, $link->error);
28+
echo "done";
29+
} else {
30+
echo "bug";
31+
}
32+
$link->close();
33+
?>
34+
--CLEAN--
35+
<?php
36+
require_once('connect.inc');
37+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
38+
printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
39+
$host, $user, $db, $port, $socket);
40+
}
41+
if (!$link->query($link, 'DROP TABLE IF EXISTS test')) {
42+
printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43+
}
44+
$link->close();
45+
unlink('bug77956.data');
46+
?>
47+
--EXPECTF--
48+
Warning: mysqli::query(): LOAD DATA LOCAL INFILE forbidden in %s on line %d
49+
[006] [2000] LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile
50+
done

ext/mysqlnd/mysqlnd_loaddata.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * const filenam
156156

157157
if (!(conn->options->flags & CLIENT_LOCAL_FILES)) {
158158
php_error_docref(NULL, E_WARNING, "LOAD DATA LOCAL INFILE forbidden");
159+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE,
160+
"LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile");
159161
/* write empty packet to server */
160162
ret = net->data->m.send(net, vio, empty_packet, 0, conn->stats, conn->error_info);
161163
*is_warning = TRUE;

0 commit comments

Comments
 (0)