Skip to content

Commit 6f81ac5

Browse files
committed
BUG#36765200: python mysql connector 8.3.0 raise %-.100s:%u when input a wrong host
This patch fixes the issue where 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. Change-Id: I9e4e469fc8294e1766a4b787d9017f43de339e1a
1 parent da48d02 commit 6f81ac5

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ v9.1.0
1919
- WL#16307: Remove Python 3.8 support
2020
- WL#16306: Add support for Python 3.13
2121
- BUG#37013057: mysql-connector-python Parameterized query SQL injection
22+
- BUG#36765200: python mysql connector 8.3.0 raise %-.100s:%u when input a wrong host
2223
- BUG#36577957: Update charset/collation description indicate this is 16 bits
2324

2425
v9.0.0

mysql-connector-python/lib/mysql/connector/network.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _strioerror(err: IOError) -> str:
7171
7272
This function reformats the IOError error message.
7373
"""
74-
return str(err) if not err.errno else f"{err.errno} {err.strerror}"
74+
return str(err) if not err.errno else f"Errno {err.errno}: {err.strerror}"
7575

7676

7777
class NetworkBroker(ABC):
@@ -746,7 +746,8 @@ def open_connection(self) -> None:
746746
addrinfo = addrinfos[0]
747747
except IOError as err:
748748
raise InterfaceError(
749-
errno=2003, values=(self.address, _strioerror(err))
749+
errno=2003,
750+
values=(self.server_host, self.server_port, _strioerror(err)),
750751
) from err
751752

752753
(self._family, socktype, proto, _, sockaddr) = addrinfo

mysql-connector-python/tests/test_bugs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8785,3 +8785,30 @@ async def test_execute_dict_based_injection(self):
87858785
async def test_execute_tuple_based_injection(self):
87868786
for cur_config in self.bug_37013057.cur_flavors:
87878787
await self._run_execute(dict_based=False, cur_config=cur_config)
8788+
8789+
class BugOra36765200(tests.MySQLConnectorTests):
8790+
"""BUG#367652000: python mysql connector 8.3.0 raise %-.100s:%u when input a wrong host
8791+
8792+
Unformatted error message is being shown to the client if an unreachable host is passed
8793+
via the connection arguments while connecting with a MySQL server using pure-python
8794+
implementation of Connector/Python.
8795+
8796+
This patch fixes this issue by changing the error log message structure.
8797+
"""
8798+
8799+
def test_incorrect_host_err_msg(self):
8800+
config = tests.get_mysql_config()
8801+
config["host"] = "foo.bar"
8802+
config["unix_socket"] = None
8803+
cnx = MySQLConnection
8804+
8805+
self.assertRaises(errors.InterfaceError, cnx, **config)
8806+
try:
8807+
with cnx(**config) as _:
8808+
pass
8809+
except errors.InterfaceError as err:
8810+
self.assertNotIn(
8811+
"%-.100s:%u",
8812+
str(err),
8813+
"Error message cannot contain unstructured bind address"
8814+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy