Skip to content

Commit 609268f

Browse files
committed
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.
1 parent 5498e2d commit 609268f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
3434
- Build with OpenSSL < 1.1.1 (#194)
3535
- Add `ExecuteAsync` and `ExecuteTyped` to common connector interface (#62)
3636
- Race conditions in methods of `Future` type (#195)
37+
- Usage of nil pointer in Connection.peekFuture (#195)
3738

3839
## [1.6.0] - 2022-06-01
3940

connection.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -949,11 +949,12 @@ func (conn *Connection) peekFuture(reqid uint32) (fut *Future) {
949949
defer shard.rmut.Unlock()
950950

951951
if conn.opts.Timeout > 0 {
952-
fut = conn.getFutureImp(reqid, true)
953-
pair := &shard.requests[pos]
954-
*pair.last = fut
955-
pair.last = &fut.next
956-
fut.timeout = time.Since(epoch) + conn.opts.Timeout
952+
if fut = conn.getFutureImp(reqid, true); fut != nil {
953+
pair := &shard.requests[pos]
954+
*pair.last = fut
955+
pair.last = &fut.next
956+
fut.timeout = time.Since(epoch) + conn.opts.Timeout
957+
}
957958
} else {
958959
fut = conn.getFutureImp(reqid, false)
959960
}

0 commit comments

Comments
 (0)