Bug #80001 [NEW]: SSL connection error is not reported via mysqli::$connect_error
From: morozov at tut dot by
Operating system: Linux
PHP version: 7.4.9
Package: MySQLi related
Bug Type: Bug
Bug description:SSL connection error is not reported via mysqli::$connect_error
Description:
------------
According to the documentation, mysqli::$connect_error returns the last
error message string from the last call to mysqli_connect(). NULL is
returned if no error occurred.
However, if the underlying connection error is related to SSL,
mysqli::$connect_error remains NULL which is incorrect.
The reproduction script tries to connect to a MySQL server running in a
https://hub.docker.com/_/mysql container and relies on
the fact that the
CN in the autogenerated server certificate doesn't match its hostname.
The same problem is reproducible with literally any SSL error.
Test script:
---------------
<?php
$conn = mysqli_init();
$conn->ssl_set('client-key.pem', 'client-cert.pem', 'ca.pem',
'', '');
if (!$conn->real_connect('127.0.0.1', 'root', '',
'mysql')) {
var_dump($conn->connect_error);
exit(1);
}
Expected result:
----------------
$conn->connect_error contains a string with an error message.
Actual result:
--------------
Warning: mysqli::real_connect(): Peer certificate
CN=`MySQL_Server_8.0.18_Auto_Generated_Server_Certificate' did not match
expected CN=`127.0.0.1' in /home/morozov/mysqi-tls.php on line 7
Warning: mysqli::real_connect(): Cannot connect to MySQL by using SSL in
/home/morozov/mysqi-tls.php on line 7
Warning: mysqli::real_connect(): [2002] (trying to connect via (null))
in /home/morozov/mysqi-tls.php on line 7
Warning: mysqli::real_connect(): (HY000/2002): in
/home/morozov/mysqi-tls.php on line 7
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=80001&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80001&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80001&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80001&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80001&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80001&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80001&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80001&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80001&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80001&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80001&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80001&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80001&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80001&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80001&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80001&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80001&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80001&r=mysqlcfg
Thread (6 messages)
- morozov at tut dot by