Skip to content

Commit 9134f9e

Browse files
committed
Merge branch 'PHP-5.6' into PHP-7.0
Conflicts: ext/mysql/php_mysql.c
2 parents 0dce4be + 25439e9 commit 9134f9e

File tree

9 files changed

+103
-11
lines changed

9 files changed

+103
-11
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 #70898, #70895 (null ptr deref and segfault with crafted callable).
1111
(Anatol, Laruence)
1212

13+
- Mysqlnd:
14+
. Fixed bug #68077 (LOAD DATA LOCAL INFILE / open_basedir restriction).
15+
(Laruence)
16+
1317
- OCI8:
1418
. Fixed memory leak with LOBs. (Senthil)
1519

ext/ldap/ldap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,12 @@ PHP_FUNCTION(ldap_connect)
368368
}
369369

370370
url = emalloc(urllen);
371-
snprintf( url, urllen, "ldap://%s:%ld", host ? host : "", port );
371+
if (host && (strchr(host, ':') != NULL)) {
372+
/* Legacy support for host:port */
373+
snprintf( url, urllen, "ldap://%s", host );
374+
} else {
375+
snprintf( url, urllen, "ldap://%s:%ld", host ? host : "", port );
376+
}
372377
}
373378

374379
#ifdef LDAP_API_FEATURE_X_OPENLDAP

ext/ldap/tests/ldap_connect_variation.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var_dump($link);
2828
// bad hostname (connect should work, not bind)
2929
$link = ldap_connect("nonexistent" . $host);
3030
var_dump($link);
31+
32+
// Legacy host:port syntax
33+
$link = ldap_connect("$host:$port");
34+
var_dump($link);
3135
?>
3236
===DONE===
3337
--EXPECTF--
@@ -36,4 +40,5 @@ resource(%d) of type (ldap link)
3640
resource(%d) of type (ldap link)
3741
resource(%d) of type (ldap link)
3842
resource(%d) of type (ldap link)
43+
resource(%d) of type (ldap link)
3944
===DONE===

ext/mysqli/mysqli_api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@ PHP_FUNCTION(mysqli_options)
17761776
}
17771777
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
17781778

1779+
#if !defined(MYSQLI_USE_MYSQLND)
17791780
#if PHP_API_VERSION < 20100412
17801781
if ((PG(open_basedir) && PG(open_basedir)[0] != '\0') || PG(safe_mode)) {
17811782
#else
@@ -1785,6 +1786,7 @@ PHP_FUNCTION(mysqli_options)
17851786
RETURN_FALSE;
17861787
}
17871788
}
1789+
#endif
17881790
expected_type = mysqli_options_get_option_zval_type(mysql_option);
17891791
if (expected_type != Z_TYPE_P(mysql_value)) {
17901792
switch (expected_type) {

ext/mysqli/mysqli_nonapi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
118118
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
119119
/* remove some insecure options */
120120
flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
121+
#if !defined(MYSQLI_USE_MYSQLND)
121122
if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
122123
flags &= ~CLIENT_LOCAL_FILES;
123124
}
125+
#endif
124126
}
125127

126128
if (!socket_len || !socket) {

ext/mysqli/tests/bug68077.phpt

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

ext/mysqli/tests/mysqli_options_openbasedir.phpt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ require_once('skipifconnectfailure.inc');
88
?>
99
--FILE--
1010
<?php
11-
require_once('connect.inc');
12-
ini_set("open_basedir", __DIR__);
13-
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
14-
printf("[001] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
11+
require_once('connect.inc');
12+
ini_set("open_basedir", __DIR__);
13+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
14+
printf("[001] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
1515

16+
if ($IS_MYSQLND) {
17+
if (true !== mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, 1))
18+
printf("[002] Can not set MYSQLI_OPT_LOCAL_INFILE although open_basedir is set!\n");
19+
20+
} else {
1621
if (false !== mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, 1))
1722
printf("[002] Can set MYSQLI_OPT_LOCAL_INFILE although open_basedir is set!\n");
1823

19-
mysqli_close($link);
20-
print "done!";
24+
}
25+
mysqli_close($link);
26+
print "done!";
2127
?>
2228
--EXPECTF--
2329
done!

ext/mysqlnd/mysqlnd.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_updated_connect_flags)(MYSQLND_CONN_DATA *
756756

757757
mysql_flags |= conn->options->flags; /* use the flags from set_client_option() */
758758

759-
if (PG(open_basedir) && strlen(PG(open_basedir))) {
760-
mysql_flags ^= CLIENT_LOCAL_FILES;
761-
}
762-
763759
#ifndef MYSQLND_COMPRESSION_ENABLED
764760
if (mysql_flags & CLIENT_COMPRESS) {
765761
mysql_flags &= ~CLIENT_COMPRESS;

ext/pdo_mysql/mysql_driver.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
632632
goto cleanup;
633633
}
634634

635+
#ifndef PDO_USE_MYSQLND
635636
#if PHP_API_VERSION < 20100412
636637
if ((PG(open_basedir) && PG(open_basedir)[0] != '\0') || PG(safe_mode))
637638
#else
@@ -640,6 +641,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
640641
{
641642
local_infile = 0;
642643
}
644+
#endif
643645
#if defined(MYSQL_OPT_LOCAL_INFILE) || defined(PDO_USE_MYSQLND)
644646
if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE, (const char *)&local_infile)) {
645647
pdo_mysql_error(dbh);

0 commit comments

Comments
 (0)