From 609268f8a6143aba7332150f226b3836ac7ee2f7 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Tue, 19 Jul 2022 14:21:15 +0300 Subject: [PATCH] bugfix: usage of nil in Connection.peekFuture() It may be possible to get a nil value from conn.getFutureImp(). We need to check the value before using. --- CHANGELOG.md | 1 + connection.go | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d32d36517..3a840c13c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. - Build with OpenSSL < 1.1.1 (#194) - Add `ExecuteAsync` and `ExecuteTyped` to common connector interface (#62) - Race conditions in methods of `Future` type (#195) +- Usage of nil pointer in Connection.peekFuture (#195) ## [1.6.0] - 2022-06-01 diff --git a/connection.go b/connection.go index 6a1829837..e5595b5b1 100644 --- a/connection.go +++ b/connection.go @@ -949,11 +949,12 @@ func (conn *Connection) peekFuture(reqid uint32) (fut *Future) { defer shard.rmut.Unlock() if conn.opts.Timeout > 0 { - fut = conn.getFutureImp(reqid, true) - pair := &shard.requests[pos] - *pair.last = fut - pair.last = &fut.next - fut.timeout = time.Since(epoch) + conn.opts.Timeout + if fut = conn.getFutureImp(reqid, true); fut != nil { + pair := &shard.requests[pos] + *pair.last = fut + pair.last = &fut.next + fut.timeout = time.Since(epoch) + conn.opts.Timeout + } } else { fut = conn.getFutureImp(reqid, false) }