ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Critical - P2
    • None
    • Affects Version/s: 8.0.9
    • Component/s: None
    • DB Integration & Observability
    • ALL
    • QE 2026-11-23
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I found a potential null pointer dereference in getDBClientWithAutoEncryptionRef() in MongoDB 8.0.9:

      https://github.com/mongodb/mongo/blob/r8.0.9/src/mongo/scripting/mozjs/mongo.cpp#L148-L156

      In this method, the return value of JS::GetMaybePtrFromReservedSlot() is dereferenced without checking it for nullptr:

      {{auto ret = JS::GetMaybePtrFromReservedSlot<std::shared_ptr<DBClientWithAutoEncryption>>(
      args.thisv().toObjectOrNull(), MongoBase::DBClientWithAutoEncryptionSlot);

      uassert(
      ErrorCodes::BadValue, "Trying to get connection for closed Mongo object", *ret != nullptr);

      return *ret;}}

      The GetMaybePtrFromReservedSlot() function may return nullptr if the requested pointer is not available in the reserved slot.

      If ret is nullptr, the expression *ret != nullptr dereferences a null pointer while evaluating the condition passed to uassert, potentially leading to undefined behavior before the assertion can handle the error.

      The existing uassert only checks whether the stored std::shared_ptr is null. It does not verify that the pointer returned by GetMaybePtrFromReservedSlot() is valid.

      A possible fix is to add an explicit check before dereferencing ret:

      {{auto ret = JS::GetMaybePtrFromReservedSlot<std::shared_ptr<DBClientWithAutoEncryption>>(
      args.thisv().toObjectOrNull(), MongoBase::DBClientWithAutoEncryptionSlot);

      invariant(ret);

      uassert(
      ErrorCodes::BadValue, "Trying to get connection for closed Mongo object", *ret != nullptr);

      return *ret;}}

      This would explicitly enforce the expected precondition and prevent an unchecked null pointer dereference.

      Found by Linux Verification Center (linuxtesting.org) with SVACE.

      Reporter: Grebennikov Aleksandr (grebennikov@bmstu.ru)

            Assignee:
            Nicola Cabiddu
            Reporter:
            Александр Гребенников (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: