Skip to content

Commit f7acb70

Browse files
committed
BUG21090014: Fix handshake with MySQL server 5.5.8
We do not check for the end byte to be \x00 for MySQL Server 5.5.8. In this particular version of the server, the end byte was erroneously not send. Unit tests are updated.
1 parent 68ded79 commit f7acb70

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/mysql/connector/protocol.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def parse_handshake(self, packet):
173173
capabilities2,
174174
auth_data_length
175175
) = struct_unpack('<I8sx2sBH2sBxxxxxxxxxx', packet[0:31])
176+
res['server_version_original'] = res['server_version_original'].decode()
176177

177178
packet = packet[31:]
178179

@@ -186,15 +187,19 @@ def parse_handshake(self, packet):
186187
auth_data2 = auth_data2[:-1]
187188

188189
if capabilities & ClientFlag.PLUGIN_AUTH:
189-
(packet, res['auth_plugin']) = utils.read_string(
190-
packet, end=b'\x00')
190+
if (b'\x00' not in packet
191+
and res['server_version_original'].startswith("5.5.8")):
192+
# MySQL server 5.5.8 has a bug where end byte is not send
193+
(packet, res['auth_plugin']) = (b'', packet)
194+
else:
195+
(packet, res['auth_plugin']) = utils.read_string(
196+
packet, end=b'\x00')
191197
res['auth_plugin'] = res['auth_plugin'].decode('utf-8')
192198
else:
193199
res['auth_plugin'] = 'mysql_native_password'
194200

195201
res['auth_data'] = auth_data1 + auth_data2
196202
res['capabilities'] = capabilities
197-
res['server_version_original'] = res['server_version_original'].decode()
198203
return res
199204

200205
def parse_ok(self, packet):

tests/test_protocol.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ def test_parse_handshake(self):
231231
res = self._protocol.parse_handshake(handshake)
232232
self.assertEqual(exp, res)
233233

234+
# Test when end byte \x00 is not present for server 5.5.8
235+
handshake = handshake[:-1]
236+
res = self._protocol.parse_handshake(handshake)
237+
self.assertEqual(exp, res)
238+
234239
def test_parse_ok(self):
235240
"""Parse OK-packet sent by MySQL"""
236241
res = self._protocol.parse_ok(OK_PACKET)

0 commit comments

Comments
 (0)