From edd28f1e6dd7cb2fe053857b72e43a8defa8d718 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Sun, 25 Mar 2018 16:58:27 -0700 Subject: [release-branch.go1.10] database/sql: check for nil connRequest.conn before use The connRequest may return a nil conn value. However in a rare case that is difficult to test for it was being passed to DB.putConn without a nil check. This was an error as this made no sense if the driverConn is nil. This also caused a panic in putConn. A test for this would be nice, but didn't find a sane way to test for this condition. Updates #24445 Fixes #25235 Change-Id: I827316e856788a5a3ced913f129bb5869b7bcf68 Reviewed-on: https://go-review.googlesource.com/102477 Run-TryBot: Daniel Theophanes TryBot-Result: Gobot Gobot Reviewed-by: Alexey Palazhchenko Reviewed-by: Brad Fitzpatrick (cherry picked from commit b98ffdf859f0fec2acb1765bf5b62ce1e4587c2b) Reviewed-on: https://go-review.googlesource.com/c/146778 Run-TryBot: Brad Fitzpatrick Reviewed-by: Katie Hockman --- src/database/sql/sql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index 8f5588ed26..719be91043 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -1070,7 +1070,7 @@ func (db *DB) conn(ctx context.Context, strategy connReuseStrategy) (*driverConn select { default: case ret, ok := <-req: - if ok { + if ok && ret.conn != nil { db.putConn(ret.conn, ret.err, false) } } -- cgit v1.2.3-54-g00ecf