Skip to content

Commit

Permalink
BUG#36765200: python mysql connector 8.3.0 raise %-.100s:%u when inpu…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
SubCoder1 committed Sep 12, 2024
1 parent da48d02 commit 6f81ac5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions mysql-connector-python/lib/mysql/connector/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions mysql-connector-python/tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 6f81ac5

Please sign in to comment.