Skip to content
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

Proper error handling in handleAuthResult #1191

Closed
MrBTTF opened this issue Feb 18, 2021 · 0 comments
Closed

Proper error handling in handleAuthResult #1191

MrBTTF opened this issue Feb 18, 2021 · 0 comments

Comments

@MrBTTF
Copy link
Contributor

MrBTTF commented Feb 18, 2021

Issue description

If block is nil, in line 375 ParsePKIXPublicKey will panic. It happened to me when I was trying to connect GCP sql database and it responded with Access denied for user 'user'@'cloudsqlproxy~xx.xx.xx.x' (using password: YES)

mysql/auth.go

Lines 374 to 375 in fe2230a

block, _ := pem.Decode(data[1:])
pkix, err := x509.ParsePKIXPublicKey(block.Bytes)

Error log

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x6a44f2]

goroutine 1 [running]:
github.com/go-sql-driver/mysql.(*mysqlConn).handleAuthResult(0xc0000a79e0, 0xc0004c8be8, 0x14, 0x14, 0xc0004c8bd0, 0x15, 0x0, 0x0)
	/root/go/pkg/mod/github.com/go-sql-driver/mysql@v1.5.0/auth.go:380 +0x732
github.com/go-sql-driver/mysql.(*connector).Connect(0xc0000103e8, 0xb69bf0, 0xc0000240d8, 0x0, 0x0, 0x0, 0x0)
	/root/go/pkg/mod/github.com/go-sql-driver/mysql@v1.5.0/connector.go:109 +0x596
database/sql.(*DB).conn(0xc000110ea0, 0xb69bf0, 0xc0000240d8, 0xc00025fb01, 0x4e34d7, 0xc0000811e0, 0xc00008e500)
	/usr/local/go/src/database/sql/sql.go:1301 +0x184
database/sql.(*DB).PingContext(0xc000110ea0, 0xb69bf0, 0xc0000240d8, 0x1, 0x1)
	/usr/local/go/src/database/sql/sql.go:799 +0x90
database/sql.(*DB).Ping(...)
	/usr/local/go/src/database/sql/sql.go:817
github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql.DialCfg(0xc00025fd68, 0xc00025fd68, 0x52632e, 0xc0002acbd0)
	/root/go/pkg/mod/github.com/!google!cloud!platform/cloudsql-proxy@v1.19.1/proxy/dialers/mysql/hook.go:93 +0x1c5
github.com/qreuz/common-go/pkg/utils.InitDB(0xc0000f78c0, 0xaaf751, 0x9, 0xc0000d8600, 0x0, 0xc00025feb0, 0x52a3a5)
...

Suggestion

I suggest to handle it in this way

block, rest := pem.Decode(data[1:])
if block == nil {
	return fmt.Errorf("No Pem data found, data: %s", rest)
}

Configuration

Driver version (or git SHA): v1.5.0

Go version: go version go1.16 linux/amd64

Server version: MySQL 8

@MrBTTF MrBTTF mentioned this issue Mar 1, 2021
5 tasks
@MrBTTF MrBTTF closed this as completed Apr 4, 2021
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

No branches or pull requests

1 participant