Skip to content

Commit dc3b75c

Browse files
committed
Add NULL terminator to mysql_clear_password. Fixes #703
1 parent c28126e commit dc3b75c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
538538
Log.Error("Session{0} needs a secure connection to use AuthenticationMethod '{1}'", m_logArguments);
539539
throw new MySqlException(MySqlErrorCode.UnableToConnectToHost, "Authentication method '{0}' requires a secure connection.".FormatInvariant(switchRequest.Name));
540540
}
541-
payload = new PayloadData(Encoding.UTF8.GetBytes(cs.Password));
541+
// send the password as a NULL-terminated UTF-8 string
542+
var passwordBytes = Encoding.UTF8.GetBytes(cs.Password);
543+
Array.Resize(ref passwordBytes, passwordBytes.Length + 1);
544+
payload = new PayloadData(passwordBytes);
542545
await SendReplyAsync(payload, ioBehavior, cancellationToken).ConfigureAwait(false);
543546
return await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
544547

0 commit comments

Comments
 (0)