|
|
@@ -9,6 +9,7 @@
|
|
|
package mysql
|
|
|
|
|
|
import (
|
|
|
+ "bytes"
|
|
|
"errors"
|
|
|
"net"
|
|
|
"testing"
|
|
|
@@ -280,3 +281,37 @@ func TestReadPacketFail(t *testing.T) {
|
|
|
t.Errorf("expected ErrInvalidConn, got %v", err)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// https://github.com/go-sql-driver/mysql/pull/801
|
|
|
+// not-NUL terminated plugin_name in init packet
|
|
|
+func TestRegression801(t *testing.T) {
|
|
|
+ conn := new(mockConn)
|
|
|
+ mc := &mysqlConn{
|
|
|
+ buf: newBuffer(conn),
|
|
|
+ cfg: new(Config),
|
|
|
+ sequence: 42,
|
|
|
+ closech: make(chan struct{}),
|
|
|
+ }
|
|
|
+
|
|
|
+ conn.data = []byte{72, 0, 0, 42, 10, 53, 46, 53, 46, 56, 0, 165, 0, 0, 0,
|
|
|
+ 60, 70, 63, 58, 68, 104, 34, 97, 0, 223, 247, 33, 2, 0, 15, 128, 21, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 120, 114, 47, 85, 75, 109, 99, 51, 77,
|
|
|
+ 50, 64, 0, 109, 121, 115, 113, 108, 95, 110, 97, 116, 105, 118, 101, 95,
|
|
|
+ 112, 97, 115, 115, 119, 111, 114, 100}
|
|
|
+ conn.maxReads = 1
|
|
|
+
|
|
|
+ authData, pluginName, err := mc.readInitPacket()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("got error: %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if pluginName != "mysql_native_password" {
|
|
|
+ t.Errorf("expected plugin name 'mysql_native_password', got '%s'", pluginName)
|
|
|
+ }
|
|
|
+
|
|
|
+ expectedAuthData := []byte{60, 70, 63, 58, 68, 104, 34, 97, 98, 120, 114,
|
|
|
+ 47, 85, 75, 109, 99, 51, 77, 50, 64}
|
|
|
+ if !bytes.Equal(authData, expectedAuthData) {
|
|
|
+ t.Errorf("expected authData '%v', got '%v'", expectedAuthData, authData)
|
|
|
+ }
|
|
|
+}
|