8000 Fix generating authentication response with long strings · PyMySQL/PyMySQL@ab82515 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab82515

Browse files
committed
Fix generating authentication response with long strings
MySQL protocol uses special rules for string longer than 251 characters.
1 parent 6ccbecc commit ab82515

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pymysql/connections.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -879,10 +879,11 @@ def _request_authentication(self):
879879
else:
880880
authresp = b"\0" # empty password
881881

882-
if self.server_capabilities & CLIENT.PLUGIN_AUTH_LENENC_CLIENT_DATA:
882+
if (
883+
self.server_capabilities & CLIENT.PLUGIN_AUTH_LENENC_CLIENT_DATA
884+
or self.server_capabilities & CLIENT.SECURE_CONNECTION
885+
):
883886
data += _lenenc_int(len(authresp)) + authresp
884-
elif self.server_capabilities & CLIENT.SECURE_CONNECTION:
885-
data += struct.pack("B", len(authresp)) + authresp
886887
else: # pragma: no cover - not testing against servers without secure auth (>=5.0)
887888
data += authresp + b"\0"
888889

@@ -898,10 +899,10 @@ def _request_authentication(self):
898899
connect_attrs = b""
899900
for k, v in self._connect_attrs.items():
900901
k = k.encode("utf-8")
901-
connect_attrs += struct.pack("B", len(k)) + k
902+
connect_attrs += _lenenc_int(len(k)) + k
902903
v = v.encode("utf-8")
903-
connect_attrs += struct.pack("B", len(v)) + v
904-
data += struct.pack("B", len(connect_attrs)) + connect_attrs
904+
connect_attrs += _lenenc_int(len(v)) + v
905+
data += _lenenc_int(len(connect_attrs)) + connect_attrs
905906

906907
self.write_packet(data)
907908
auth_packet = self._read_packet()

0 commit comments

Comments
 (0)
0