[SERVER-65705] Coverity analysis defect 122087: Division or modulo by zero Created: 15/Apr/22  Updated: 29/Oct/23  Resolved: 26/Apr/22

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 6.0.0-rc3, 6.1.0-rc0

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

Issue Links:
Backports
Duplicate
is duplicated by SERVER-65326 Coverity analysis defect 122032: Divi... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.0
Sprint: Sharding EMEA 2022-05-02
Participants:

 Description   

Division or modulo by zero

The program will have undefined behavior, likely a crash. Division or modulo by zero results in undefined behavior.
/src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp:111: DIVIDE_BY_ZERO 122087 Assigning: "numRecords" = "autoColl->numRecords(opCtx)". The value of "numRecords" is now 0.
/src/mongo/db/s/shardsvr_get_stats_for_balancing_command.cpp:130: DIVIDE_BY_ZERO 122087 In expression "dataSizeBytes / numRecords", division by expression "numRecords" which may be zero has undefined behavior.



 Comments   
Comment by Githook User [ 27/Apr/22 ]

Author:

{'name': 'Tommaso Tocci', 'email': 'tommaso.tocci@mongodb.com', 'username': 'toto-dev'}

Message: SERVER-65705 avoid division by zero in ShardsvrGetStatsForBalancing

(cherry picked from commit 1aa6b2bba7b60fd4ffbcaf1c7c9c5a23a09718a0)
Branch: v6.0
https://github.com/mongodb/mongo/commit/dfbc0da153ecbebb86c27bca77a1c9652896fc36

Comment by Githook User [ 26/Apr/22 ]

Author:

{'name': 'Tommaso Tocci', 'email': 'tommaso.tocci@mongodb.com', 'username': 'toto-dev'}

Message: SERVER-65705 avoid division by zero in ShardsvrGetStatsForBalancing
Branch: master
https://github.com/mongodb/mongo/commit/1aa6b2bba7b60fd4ffbcaf1c7c9c5a23a09718a0

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