[SERVER-70518] Coverity analysis defect 122973: Dereference after null check Created: 13/Oct/22  Updated: 27/Oct/23  Resolved: 14/Aug/23

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Coverity Collector User Assignee: Rachita Dhawan
Resolution: Gone away Votes: 0
Labels: coverity, neweng, sharding-nyc-subteam1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
is caused by SERVER-62175 Mongos fails to attach RetryableWrite... Closed
Assigned Teams:
Sharding NYC
Operating System: ALL
Participants:
Story Points: 2

 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/s/commands/strategy.cpp:492: FORWARD_NULL 122973 Comparing "command" to null implies that "command" might be null.



 Comments   
Comment by Rachita Dhawan [ 14/Aug/23 ]

I agree that this can be closed now.kyle.suarez@mongodb.com

Comment by Kyle Suarez [ 11/Aug/23 ]

Looking at the latest master, it seems this is actually no longer an issue as there is now an early bailout if command is null: https://github.com/mongodb/mongo/blob/05ca90890bd0bb200bcef51eb3a9712cf60557b0/src/mongo/s/commands/strategy.cpp#L512-L513.

max.hirschhorn@mongodb.com, rachita.dhawan@mongodb.com, any objection to closing this as either Fixed or Gone Away?

Comment by Max Hirschhorn [ 31/Oct/22 ]

One option is to add an invariant(command) immediately below this line to reflect how _osi is only a truthy value when _rec->setCommand() has been called. Another option is to swap the order of NotPrimaryErrorTracker and command->incrementCommandsFailed() to be able to early return when _rec->setCommand() hasn't been called.

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