Skip to content

Commit fb0ce27

Browse files
committed
Handle extra byte in ext-salt. Fixes #1606
1 parent 70aceff commit fb0ce27

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,15 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
943943
payload = new([]);
944944
await SendReplyAsync(payload, ioBehavior, cancellationToken).ConfigureAwait(false);
945945
payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
946+
var extendedSalt = payload.Span;
946947

947-
Span<byte> combinedData = stackalloc byte[switchRequest.Data.Length + payload.Span.Length];
948+
// MariaDB 11.8.4 sends an extra 0x01 byte at the beginning of ext-salt; cf. https://mariadb.com/docs/server/reference/clientserver-protocol/1-connecting/connection#parsec-plugin
949+
if (extendedSalt.Length == 21 && extendedSalt[0] == 1 && extendedSalt[1] == 'P')
950+
extendedSalt = extendedSalt[1..];
951+
952+
Span<byte> combinedData = stackalloc byte[switchRequest.Data.Length + extendedSalt.Length];
948953
switchRequest.Data.CopyTo(combinedData);
949-
payload.Span.CopyTo(combinedData.Slice(switchRequest.Data.Length));
954+
extendedSalt.CopyTo(combinedData.Slice(switchRequest.Data.Length));
950955

951956
parsecPlugin3.CreateResponseAndPasswordHash(password, combinedData, out var parsecResponse, out m_passwordHash);
952957
payload = new(parsecResponse);

0 commit comments

Comments
 (0)