Skip to content

Commit 0e51ee2

Browse files
author
Jose Ramirez
committed
Bug #27532931 CONN WITH BLANK PWD FAILS FOR USER CREATED USING MYSQL_NATIVE_PASSWORD-WL#11285
* Updated the NativePasswordPlugin to handle the GetPassword() method returning a null object. * Fixed bug in the authentication process where the SendPacket() didn't take into account empty byte arrays and would result in not allowing empty passwords for mysql_native_password auth plugin during an authentication change.
1 parent 3d68181 commit 0e51ee2

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

Source/MySql.Data/Authentication/MySQLAuthenticationPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private void ContinueAuthentication(byte[] data = null)
207207
packet.Clear();
208208
byte[] moreData = MoreData(data);
209209

210-
while (moreData != null && moreData.Length > 0)
210+
while (moreData != null)
211211
{
212212
packet.Clear();
213213
packet.Write(moreData);

Source/MySql.Data/Authentication/NativePasswordPlugins.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2012, 2017 Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2012, 2018, Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -55,7 +55,7 @@ protected override void SetAuthData(byte[] data)
5555

5656
protected override byte[] MoreData(byte[] data)
5757
{
58-
byte[] passBytes = GetPassword() as byte[];
58+
byte[] passBytes = (GetPassword() ?? new byte[1]) as byte[];
5959
byte[] buffer = new byte[passBytes.Length - 1];
6060
Array.Copy(passBytes, 1, buffer, 0, passBytes.Length - 1);
6161
return buffer;

Source/MySql.Data/MySqlStream.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright © 2004, 2018, Oracle and/or its affiliates. All rights reserved.
22
//
33
// MySQL Connector/NET is licensed under the terms of the GPLv2
44
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -238,7 +238,7 @@ public void SendPacket(MySqlPacket packet)
238238
throw new MySqlException(Resources.QueryTooLarge, (int)MySqlErrorCode.PacketTooLarge);
239239

240240
int offset = 0;
241-
while (length > 0)
241+
do
242242
{
243243
int lenToSend = length > maxBlockSize ? maxBlockSize : length;
244244
buffer[offset] = (byte)(lenToSend & 0xff);
@@ -250,7 +250,7 @@ public void SendPacket(MySqlPacket packet)
250250
outStream.Flush();
251251
length -= lenToSend;
252252
offset += lenToSend;
253-
}
253+
} while (length > 0);
254254
}
255255

256256
public void SendEntirePacketDirectly(byte[] buffer, int count)

Tests/MySql.Data.Tests/MySqlConnectionTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,5 +1923,24 @@ public void EmptyPasswordOnSslDisableCachingSha2Password()
19231923
connection.Close();
19241924
}
19251925
}
1926+
1927+
[Fact]
1928+
public void EmptyPasswordOnMySqlNativePassword()
1929+
{
1930+
var pluginName = "mysql_native_password";
1931+
var builder = new MySqlConnectionStringBuilder();
1932+
builder.UserID = "testNtvPass";
1933+
builder.Password = "";
1934+
builder.Server = st.conn.Settings.Server;
1935+
builder.Port = st.conn.Settings.Port;
1936+
st.CreateUser(builder.UserID, builder.Password, pluginName);
1937+
1938+
using (var connection = new MySqlConnection(builder.ConnectionString))
1939+
{
1940+
connection.Open();
1941+
Assert.True(connection.State == ConnectionState.Open);
1942+
connection.Close();
1943+
}
1944+
}
19261945
}
19271946
}

0 commit comments

Comments
 (0)