Skip to content

Commit 44c24df

Browse files
packets: add regression test for #801 (#802)
Updates #801
1 parent 5afaf12 commit 44c24df

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

packets_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package mysql
1010

1111
import (
12+
"bytes"
1213
"errors"
1314
"net"
1415
"testing"
@@ -280,3 +281,37 @@ func TestReadPacketFail(t *testing.T) {
280281
t.Errorf("expected ErrInvalidConn, got %v", err)
281282
}
282283
}
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

Comments
 (0)