diff --git a/CHANGES.txt b/CHANGES.txt index 2e6d99b3..26c54da7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,7 @@ v9.1.0 - WL#16307: Remove Python 3.8 support - WL#16306: Add support for Python 3.13 - BUG#37013057: mysql-connector-python Parameterized query SQL injection +- BUG#36765200: python mysql connector 8.3.0 raise %-.100s:%u when input a wrong host - BUG#36577957: Update charset/collation description indicate this is 16 bits v9.0.0 diff --git a/mysql-connector-python/lib/mysql/connector/network.py b/mysql-connector-python/lib/mysql/connector/network.py index a47f1058..5231db8c 100644 --- a/mysql-connector-python/lib/mysql/connector/network.py +++ b/mysql-connector-python/lib/mysql/connector/network.py @@ -71,7 +71,7 @@ def _strioerror(err: IOError) -> str: This function reformats the IOError error message. """ - return str(err) if not err.errno else f"{err.errno} {err.strerror}" + return str(err) if not err.errno else f"Errno {err.errno}: {err.strerror}" class NetworkBroker(ABC): @@ -746,7 +746,8 @@ def open_connection(self) -> None: addrinfo = addrinfos[0] except IOError as err: raise InterfaceError( - errno=2003, values=(self.address, _strioerror(err)) + errno=2003, + values=(self.server_host, self.server_port, _strioerror(err)), ) from err (self._family, socktype, proto, _, sockaddr) = addrinfo diff --git a/mysql-connector-python/tests/test_bugs.py b/mysql-connector-python/tests/test_bugs.py index ca2f1bd7..37f07e55 100644 --- a/mysql-connector-python/tests/test_bugs.py +++ b/mysql-connector-python/tests/test_bugs.py @@ -8785,3 +8785,30 @@ async def test_execute_dict_based_injection(self): async def test_execute_tuple_based_injection(self): for cur_config in self.bug_37013057.cur_flavors: await self._run_execute(dict_based=False, cur_config=cur_config) + +class BugOra36765200(tests.MySQLConnectorTests): + """BUG#367652000: python mysql connector 8.3.0 raise %-.100s:%u when input a wrong host + + Unformatted error message is being shown to the client if an unreachable host is passed + via the connection arguments while connecting with a MySQL server using pure-python + implementation of Connector/Python. + + This patch fixes this issue by changing the error log message structure. + """ + + def test_incorrect_host_err_msg(self): + config = tests.get_mysql_config() + config["host"] = "foo.bar" + config["unix_socket"] = None + cnx = MySQLConnection + + self.assertRaises(errors.InterfaceError, cnx, **config) + try: + with cnx(**config) as _: + pass + except errors.InterfaceError as err: + self.assertNotIn( + "%-.100s:%u", + str(err), + "Error message cannot contain unstructured bind address" + )