[SERVER-23896] Don't allow mod by 0 in ExpressionMod::evaluateInternal() Created: 25/Apr/16  Updated: 16/May/16  Resolved: 09/May/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 3.3.6

Type: Bug Priority: Major - P3
Reporter: Coverity Collector User Assignee: James Wahlin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-23897 Coverity analysis defect 98887: Divis... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 14 (05/13/16)
Participants:

 Description   

Fix 2 potential mod by 0 cases in ExpressionMod::evaluateInternal()

Issue 1
Division or modulo by zero results in undefined behavior.

Defect 98886 (STATIC_C)
Checker DIVIDE_BY_ZERO (subcategory none)
File: /src/mongo/db/pipeline/expression.cpp
Function mongo::ExpressionMod::evaluateInternal(mongo::Variables *) const
/src/mongo/db/pipeline/expression.cpp, line: 1996
Assigning: "rightInt" = "rhs.coerceToInt()". The value of "rightInt" is now 0.

            int rightInt = rhs.coerceToInt();

/src/mongo/db/pipeline/expression.cpp, line: 1997
In expression "left % rightInt", modulo by expression "rightInt" which may be zero has undefined behavior.

            return Value(left % rightInt);

Issue 2
Division or modulo by zero results in undefined behavior.

Defect 98887 (STATIC_C)
Checker DIVIDE_BY_ZERO (subcategory none)
File: /src/mongo/db/pipeline/expression.cpp
Function mongo::ExpressionMod::evaluateInternal(mongo::Variables *) const
/src/mongo/db/pipeline/expression.cpp, line: 1990
Assigning: "rightLong" = "rhs.coerceToLong()". The value of "rightLong" is now 0.

                long long rightLong = rhs.coerceToLong();

/src/mongo/db/pipeline/expression.cpp, line: 1991
In expression "left % rightLong", modulo by expression "rightLong" which may be zero has undefined behavior.

                return Value(left % rightLong);



 Comments   
Comment by Githook User [ 09/May/16 ]

Author:

{u'username': u'jameswahlin', u'name': u'James Wahlin', u'email': u'james.wahlin@10gen.com'}

Message: SERVER-23896 Add ExpressionMod tests for infinite dividend
Branch: master
https://github.com/mongodb/mongo/commit/b31ca56158bb6bf70f5037e2d2a9403fb4558c04

Comment by Githook User [ 09/May/16 ]

Author:

{u'username': u'jameswahlin', u'name': u'James Wahlin', u'email': u'james.wahlin@10gen.com'}

Message: SERVER-23896 Additional tests for ExpressionMod
Branch: master
https://github.com/mongodb/mongo/commit/0ffad2b98d934a748ea23f70c3688a3d059f5a24

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