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

Method invocation on null MutexDebugger is undefined behavior

    • Fully Compatible
    • ALL
    • Hide

      Run smokeCppUnittests under the undefined behavior sanitizer; many tests will emit the following:

      src/mongo/util/concurrency/mutex.h:127:17: runtime error: member call on null pointer of type 'mongo::MutexDebugger'

      Show
      Run smokeCppUnittests under the undefined behavior sanitizer; many tests will emit the following: src/mongo/util/concurrency/mutex.h:127:17: runtime error: member call on null pointer of type 'mongo::MutexDebugger'

      In a _DEBUG build we enable the "MutexDebugger", which is invoked during Mutex operations. The MutexDebugger global object is an extern static in the mutex_debugger.cpp TU. There is no assurance that the static initializer for the global has run when methods are invoked.

      The MutexDebugger attempts to defend from this by checking if this == NULL, however, this is too late:

      https://github.com/mongodb/mongo/blob/master/src/mongo/util/concurrency/mutexdebugger.h#L90

      since invoking a method on a null object is undefined behavior at the point of the call.

      We should evaluate the benefits of the MutexDebugger. If it is determined to be useful, we should fix it so that it has defined behavior. Otherwise, we should remove it, or add a ubsan suppression.

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: