Skip to content

fix server response packet decoding for empty password duing connecti… #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2019

Conversation

dhlin
Copy link
Contributor

@dhlin dhlin commented Sep 23, 2019

…on handshake phase

Reference to the server doc on handshake response 41.
It's synced with mysql current source

Current version seems to be based on this doc.
There is a bit difference on the auth_response part.

How to reproduce:

  1. run the program below
  2. connect to the server using mysql --user root -p -h 127.0.0.1 --port 4000 databasename

It'll print dbName as atabasename in UseDB, missing the first character

package main 

import (
    "fmt"
    "github.com/siddontang/go-mysql/server"
    "net"
)

type handler struct{
	empty server.EmptyHandler
}

func (h handler) UseDB(dbName string) error {
	fmt.Println(dbName)
	return h.empty.UseDB(dbName)
}

func (h handler) HandleQuery(query string) (*mysql.Result, error) {
	return h.empty.HandleQuery(query)
}

func (h handler) HandleFieldList(table string, fieldWildcard string) ([]*mysql.Field, error) {
	return h.empty.HandleFieldList(table, fieldWildcard)
}

func (h handler) HandleStmtPrepare(query string) (params int, columns int, context interface{}, err error) {
	return h.empty.HandleStmtPrepare(query)
}

func (h handler) HandleStmtExecute(context interface{}, query string, args []interface{}) (*mysql.Result, error) {
	return h.empty.HandleStmtExecute(context, query, args)
}

func (h handler) HandleStmtClose(context interface{}) error {
	return h.empty.HandleStmtClose(context)
}

func (h handler) HandleOtherCommand(cmd byte, data []byte) error {
	return h.empty.HandleOtherCommand(cmd, data)
}

func main() {
	l, _ := net.Listen("tcp", "127.0.0.1:4000")
	c, _ := l.Accept()
	conn, _ := server.NewConn(c, "root", "", handler{})
	for {
		conn.HandleCommand()
	}
}

@siddontang siddontang merged commit 40afdbe into go-mysql-org:master Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants