[SERVER-50028] Coverity analysis defect 114771: Dereference after null check Created: 30/Jul/20  Updated: 29/Oct/23  Resolved: 11/Aug/20

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: 4.7.0, 4.4.2

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: coverity
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
is related to SERVER-39515 Remove the KVDatabaseCatalogEntry, KV... Closed
is related to SERVER-40717 Remove CollectionCatalogEntry and KVC... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4
Sprint: Execution Team 2020-08-24
Participants:

 Description   

Dereference after null check

Either the check against null is unnecessary, or there may be a null pointer dereference. Pointer is checked against null but then dereferenced anyway
/src/mongo/db/catalog/index_builds_manager.cpp:135: FORWARD_NULL 114771 Comparing "coll" to null implies that "coll" might be null.
/src/mongo/db/catalog/index_builds_manager.cpp:146: FORWARD_NULL 114771 Passing null pointer "coll" to "numRecords", which dereferences it. (The dereference happens because this is a virtual function call.)



 Comments   
Comment by Githook User [ 08/Sep/20 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-50028 remove unnecessary collection catalog lookup from IndexBuildsManager::startBuildingIndexForRecovery()

(cherry picked from commit bc2128c87dca30c758b87cc7bfcdfd6ab04e8e8d)
Branch: v4.4
https://github.com/mongodb/mongo/commit/11f80cd66f89d7159c313495582b36ebd7e0f302

Comment by Githook User [ 11/Aug/20 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-50028 remove unnecessary collection catalog lookup from IndexBuildsManager::startBuildingIndexForRecovery()
Branch: master
https://github.com/mongodb/mongo/commit/bc2128c87dca30c758b87cc7bfcdfd6ab04e8e8d

Comment by Benety Goh [ 07/Aug/20 ]

It is also not possible for rs to be null because we dereference it a few lines below to get a cursor.

Comment by Benety Goh [ 07/Aug/20 ]

It's not possible for coll to be nullptr because the caller retrieves the NamespaceString from the Collection.

Generated at Thu Feb 08 05:21:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.