Skip to content

Commit 50bb380

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-10964: Improve `man` page about the built-in server Fix GH-11438: mysqlnd fails to authenticate with sha256_password accounts using passwords longer than 19 characters
2 parents 47e490a + 75441d7 commit 50bb380

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

ext/mysqli/tests/gh11438.phpt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--TEST--
2+
GH-11438 (mysqlnd fails to authenticate with sha256_password accounts using passwords longer than 19 characters)
3+
--EXTENSIONS--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require_once 'skipifconnectfailure.inc';
8+
9+
ob_start();
10+
phpinfo(INFO_MODULES);
11+
$tmp = ob_get_contents();
12+
ob_end_clean();
13+
if (!stristr($tmp, "auth_plugin_sha256_password"))
14+
die("skip SHA256 auth plugin not built-in to mysqlnd");
15+
16+
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
17+
die(printf("skip: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
18+
19+
if (mysqli_get_server_version($link) < 50606)
20+
die("skip: SHA-256 requires MySQL 5.6.6+");
21+
22+
if (!($res = $link->query("SHOW PLUGINS"))) {
23+
die(sprintf("skip [%d] %s\n", $link->errno, $link->error));
24+
}
25+
26+
$found = false;
27+
while ($row = $res->fetch_assoc()) {
28+
if (($row['Name'] == 'sha256_password') && ($row['Status'] == 'ACTIVE')) {
29+
$found = true;
30+
break;
31+
}
32+
}
33+
if (!$found)
34+
die("skip SHA-256 server plugin unavailable");
35+
36+
// Ignore errors because this variable exists only in MySQL 5.6 and 5.7
37+
$link->query("SET @@session.old_passwords=2");
38+
39+
$link->query('DROP USER shatest');
40+
$link->query("DROP USER shatest@localhost");
41+
42+
if (!$link->query('CREATE USER shatest@"%" IDENTIFIED WITH sha256_password') ||
43+
!$link->query('CREATE USER shatest@"localhost" IDENTIFIED WITH sha256_password')) {
44+
die(sprintf("skip CREATE USER failed [%d] %s", $link->errno, $link->error));
45+
}
46+
47+
// Password of length 52, more than twice the length of the scramble data to ensure scramble is repeated correctly
48+
if (!$link->query('SET PASSWORD FOR shatest@"%" = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"') ||
49+
!$link->query('SET PASSWORD FOR shatest@"localhost" = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"')) {
50+
die(sprintf("skip SET PASSWORD failed [%d] %s", $link->errno, $link->error));
51+
}
52+
53+
echo "nocache";
54+
?>
55+
--FILE--
56+
<?php
57+
require_once 'connect.inc';
58+
59+
$link = new mysqli($host, 'shatest', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', null, $port, $socket);
60+
if ($link->connect_errno) {
61+
printf("[001] [%d] %s\n", $link->connect_errno, $link->connect_error);
62+
} else {
63+
if (!$res = $link->query("SELECT USER()"))
64+
printf("[002] [%d] %s\n", $link->errno, $link->error);
65+
66+
if (!$row = mysqli_fetch_assoc($res)) {
67+
printf("[003] [%d] %s\n", $link->errno, $link->error);
68+
}
69+
70+
if (!is_string($row['USER()']) || !str_starts_with($row['USER()'], 'shatest')) {
71+
printf("[004] Expecting 1 got %s/'%s'", gettype($row['USER()']), $row['USER()']);
72+
}
73+
}
74+
75+
print "done!";
76+
?>
77+
--CLEAN--
78+
<?php
79+
require_once 'connect.inc';
80+
$link->query('DROP USER shatest');
81+
$link->query('DROP USER shatest@localhost');
82+
?>
83+
--EXPECTF--
84+
done!

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,10 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
927927
char *xor_str = do_alloca(passwd_len + 1, use_heap);
928928
memcpy(xor_str, passwd, passwd_len);
929929
xor_str[passwd_len] = '\0';
930-
mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, auth_plugin_data_len);
930+
/* https://dev.mysql.com/doc/dev/mysql-server/latest/page_caching_sha2_authentication_exchanges.html
931+
* This tells us that the nonce is 20 (==SCRAMBLE_LENGTH) bytes long.
932+
* In a 5.5+ server we might get additional scramble data in php_mysqlnd_greet_read, not used by this authentication method. */
933+
mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, SCRAMBLE_LENGTH);
931934
ret = mysqlnd_sha256_public_encrypt(conn, server_public_key, passwd_len, auth_data_len, xor_str);
932935
free_alloca(xor_str, use_heap);
933936
}

sapi/cli/php.1.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ point to a local address and port PHP will listen to HTTP requests on that addre
9292
.B docroot
9393
passed by the \-t option.
9494
.LP
95+
If a PHP file is provided to the command line when the
96+
built-in web server is used, it will be used as the router script. This script
97+
will be started at each HTTP request. The script output is returned to the
98+
browser, unless the router script returns the
99+
.B false
100+
value. If so, the built-in server falls back to the default behaviour, returning
101+
the requested resource as-is by looking up the files relative to the document
102+
root specified by the \-t option, if provided.
103+
.LP
95104
If none of \-r \-f \-B \-R \-F \-E or \-S is present but a single parameter is given
96105
then this parameter is taken as the filename to parse and execute (same as
97106
with \-f). If no parameter is present then the standard input is read and

0 commit comments

Comments
 (0)