|
9 | 9 | package mysql
|
10 | 10 |
|
11 | 11 | import (
|
| 12 | + "bytes" |
12 | 13 | "errors"
|
13 | 14 | "net"
|
14 | 15 | "testing"
|
@@ -280,3 +281,37 @@ func TestReadPacketFail(t *testing.T) {
|
280 | 281 | t.Errorf("expected ErrInvalidConn, got %v", err)
|
281 | 282 | }
|
282 | 283 | }
|
| 284 | + |
| 285 | +// https://github.com/go-sql-driver/mysql/pull/801 |
| 286 | +// not-NUL terminated plugin_name in init packet |
| 287 | +func TestRegression801(t *testing.T) { |
| 288 | + conn := new(mockConn) |
| 289 | + mc := &mysqlConn{ |
| 290 | + buf: newBuffer(conn), |
| 291 | + cfg: new(Config), |
| 292 | + sequence: 42, |
| 293 | + closech: make(chan struct{}), |
| 294 | + } |
| 295 | + |
| 296 | + conn.data = []byte{72, 0, 0, 42, 10, 53, 46, 53, 46, 56, 0, 165, 0, 0, 0, |
| 297 | + 60, 70, 63, 58, 68, 104, 34, 97, 0, 223, 247, 33, 2, 0, 15, 128, 21, 0, |
| 298 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 120, 114, 47, 85, 75, 109, 99, 51, 77, |
| 299 | + 50, 64, 0, 109, 121, 115, 113, 108, 95, 110, 97, 116, 105, 118, 101, 95, |
| 300 | + 112, 97, 115, 115, 119, 111, 114, 100} |
| 301 | + conn.maxReads = 1 |
| 302 | + |
| 303 | + authData, pluginName, err := mc.readInitPacket() |
| 304 | + if err != nil { |
| 305 | + t.Fatalf("got error: %v", err) |
| 306 | + } |
| 307 | + |
| 308 | + if pluginName != "mysql_native_password" { |
| 309 | + t.Errorf("expected plugin name 'mysql_native_password', got '%s'", pluginName) |
| 310 | + } |
| 311 | + |
| 312 | + expectedAuthData := []byte{60, 70, 63, 58, 68, 104, 34, 97, 98, 120, 114, |
| 313 | + 47, 85, 75, 109, 99, 51, 77, 50, 64} |
| 314 | + if !bytes.Equal(authData, expectedAuthData) { |
| 315 | + t.Errorf("expected authData '%v', got '%v'", expectedAuthData, authData) |
| 316 | + } |
| 317 | +} |
0 commit comments