Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-23896

Don't allow mod by 0 in ExpressionMod::evaluateInternal()

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.3.6
    • None
    • Aggregation Framework
    • None
    • Fully Compatible
    • ALL
    • Query 14 (05/13/16)

    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);
      

      Attachments

        Activity

          People

            james.wahlin@mongodb.com James Wahlin
            xgen-internal-coverity Coverity Collector User
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: