[GODRIVER-2351] Collection.FindOne panics on nil FindOneOptions. Created: 19/Mar/22  Updated: 28/Oct/23  Resolved: 28/Mar/22

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: 1.8.4
Fix Version/s: 1.8.5

Type: Bug Priority: Minor - P4
Reporter: Faithfulness Alamu Assignee: Benji Rewis (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

Summary

The FindOne method on a Collection panics due to nil pointer dereference on a nil FindOneOption.

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

Problem initially discovered on v1.8.2 installation but is observed to persist in MongoDB Driver version v1.8.4.

How to Reproduce

  1. Create a collection.
  2. Create a list of options.FindOneOptions containing 1 nil options.FindOneOption.
  3. Pass the list to collection.FindOne

Additional Background

Dereferencing a nil FindOneOption results in a panic. Please see https://github.com/mongodb/mongo-go-driver/blob/630ff7cbfd2363b49bfa48968b80ce287e70ae85/mongo/collection.go#L1315|https://github.com/mongodb/mongo-go-driver/blob/630ff7cbfd2363b49bfa48968b80ce287e70ae85/mongo/collection.go#L1315],]



 Comments   
Comment by Benji Rewis (Inactive) [ 28/Mar/22 ]

Hello again, vaguemail369@gmail.com! The bug fix should be available in the upcoming version 1.8.5 of the Go driver.

Comment by Githook User [ 28/Mar/22 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2351 Add missing nil option checks (#883)
Branch: release/1.8
https://github.com/mongodb/mongo-go-driver/commit/97b1b72992b0640341dfc7c077120fce02865a6d

Comment by Githook User [ 28/Mar/22 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2351 Add missing nil option checks (#883)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/a6626e6319abd02a29faa8ed35a0de71ee17575b

Comment by Benji Rewis (Inactive) [ 22/Mar/22 ]

Thanks again for your report, vaguemail369@gmail.com. This is indeed a bug, we should have a check for opt == nil in the code you've pointed to. We're also missing similar checks in a few other, user-facing APIs. Here's a PR to add them in: https://github.com/mongodb/mongo-go-driver/pull/883.

Comment by Benji Rewis (Inactive) [ 21/Mar/22 ]

Thanks for your bug report, vaguemail369@gmail.com! We're looking into this now.

Generated at Thu Feb 08 08:38:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.