Skip to content

Commit 2eaabf0

Browse files
committed
security fix - by default 'local infile' is disabled:
- set default for mysqli.allow_local_infile=0 - explicitly disable PDO::MYSQL_ATTR_LOCAL_INFILE in case of lack of driver options - add getAttribute support for PDO::MYSQL_ATTR_LOCAL_INFILE - update existing tests where needed - add new tests [checking default value and setting on] the 'local infile' in ext/mysqli and ext/pdo_mysql
1 parent 65d8183 commit 2eaabf0

18 files changed

+148
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2019, PHP 7.1.27
44

5+
- MySQL
6+
. Disabled LOCAL INFILE by default, can be enabled using php.ini directive
7+
mysqli.allow_local_infile for mysqli, or PDO::MYSQL_ATTR_LOCAL_INFILE
8+
attribute for pdo_mysql. (Darek Slusarczyk)
59

610
10 Jan 2019, PHP 7.1.26
711

ext/mysqli/mysqli.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ PHP_INI_BEGIN()
524524
STD_PHP_INI_ENTRY("mysqli.default_socket", NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_socket, zend_mysqli_globals, mysqli_globals)
525525
#endif
526526
STD_PHP_INI_BOOLEAN("mysqli.reconnect", "0", PHP_INI_SYSTEM, OnUpdateLong, reconnect, zend_mysqli_globals, mysqli_globals)
527-
STD_PHP_INI_BOOLEAN("mysqli.allow_local_infile", "1", PHP_INI_SYSTEM, OnUpdateLong, allow_local_infile, zend_mysqli_globals, mysqli_globals)
527+
STD_PHP_INI_BOOLEAN("mysqli.allow_local_infile", "0", PHP_INI_SYSTEM, OnUpdateLong, allow_local_infile, zend_mysqli_globals, mysqli_globals)
528528
PHP_INI_END()
529529
/* }}} */
530530

@@ -549,7 +549,7 @@ static PHP_GINIT_FUNCTION(mysqli)
549549
mysqli_globals->reconnect = 0;
550550
mysqli_globals->report_mode = 0;
551551
mysqli_globals->report_ht = 0;
552-
mysqli_globals->allow_local_infile = 1;
552+
mysqli_globals->allow_local_infile = 0;
553553
#ifdef HAVE_EMBEDDED_MYSQLI
554554
mysqli_globals->embedded = 1;
555555
#else

ext/mysqli/tests/061.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if ($msg = check_local_infile_support($link, $engine))
1717

1818
mysqli_close($link);
1919
?>
20+
--INI--
21+
mysqli.allow_local_infile=1
2022
--FILE--
2123
<?php
2224
require_once("connect.inc");

ext/mysqli/tests/bug36745.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Bug #36745 (LOAD DATA LOCAL INFILE doesn't return correct error message)
55
require_once('skipif.inc');
66
require_once('skipifconnectfailure.inc');
77
?>
8+
--INI--
9+
mysqli.allow_local_infile=1
810
--FILE--
911
<?php
1012
require_once("connect.inc");

ext/mysqli/tests/bug53503.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ if ($msg = check_local_infile_support($link, $engine))
1515
mysqli_close($link);
1616

1717
?>
18+
--INI--
19+
mysqli.allow_local_infile=1
1820
--FILE--
1921
<?php
2022
require_once("connect.inc");

ext/mysqli/tests/bug68077.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ if ($msg = check_local_infile_support($link, $engine))
1717
mysqli_close($link);
1818
?>
1919
--INI--
20+
mysqli.allow_local_infile=1
21+
mysqli.allow_persistent=1
22+
mysqli.max_persistent=1
2023
open_basedir=
2124
--FILE--
2225
<?php

ext/mysqli/tests/mysqli_constants.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ require_once('skipif.inc');
66
require_once('skipifemb.inc');
77
require_once('skipifconnectfailure.inc');
88
?>
9+
--INI--
10+
mysqli.allow_local_infile=1
911
--FILE--
1012
<?php
1113
require("connect.inc");

ext/mysqli/tests/mysqli_get_client_stats.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if (!function_exists('mysqli_get_client_stats')) {
1212
--INI--
1313
mysqlnd.collect_statistics=1
1414
mysqlnd.collect_memory_statistics=1
15+
mysqli.allow_local_infile=1
1516
--FILE--
1617
<?php
1718
/*

ext/mysqli/tests/mysqli_info.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ require_once('skipif.inc');
66
require_once('skipifemb.inc');
77
require_once('skipifconnectfailure.inc');
88
?>
9+
--INI--
10+
mysqli.allow_local_infile=1
911
--FILE--
1012
<?php
1113
require_once("connect.inc");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
ensure default for local infile is off
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
?>
8+
--FILE--
9+
<?php
10+
require_once("connect.inc");
11+
12+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
13+
$res = mysqli_query($link, 'SHOW VARIABLES LIKE "local_infile"');
14+
$row = mysqli_fetch_assoc($res);
15+
echo "server: ", $row['Value'], "\n";
16+
mysqli_free_result($res);
17+
mysqli_close($link);
18+
19+
echo "connector: ", ini_get("mysqli.allow_local_infile"), "\n";
20+
21+
print "done!\n";
22+
?>
23+
--EXPECTF--
24+
server: %s
25+
connector: 0
26+
done!

0 commit comments

Comments
 (0)