ClusterServerParameterRefresher default constructor leaves _lastFcv uninitialized

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • ALL
    • Hide
      • Build the server with static analysis (Svace) enabled.
      • Observe the UNINIT.CTOR finding: _lastFcv is not initialized by the default constructor.
      • Inspect the class in the header — _lastFcv has no default member initializer and there is no user-provided constructor that initializes it; the object is default-constructed in ClusterServerParameterRefresher::start() before _lastFcv is assigned.
      Show
      Build the server with static analysis (Svace) enabled. Observe the UNINIT.CTOR finding: _lastFcv is not initialized by the default constructor. Inspect the class in the header — _lastFcv has no default member initializer and there is no user-provided constructor that initializes it; the object is default-constructed in ClusterServerParameterRefresher::start() before _lastFcv is assigned.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      In src/mongo/db/topology/cluster_parameters/cluster_server_parameter_refresher.h (formerly src/mongo/idl/cluster_server_parameter_refresher.h), the member _lastFcv of type multiversion::FeatureCompatibilityVersion (an enum class) has no default member initializer. The class currently declares no user-provided constructor, so the compiler-generated default constructor leaves _lastFcv with an indeterminate value.

      In ClusterServerParameterRefresher::start(), the object is created with std::make_unique<ClusterServerParameterRefresher>() and _lastFcv is indeterminate until it is explicitly assigned a few lines later, before the periodic refresh job that reads it (_refreshParameters() compares fcv != _lastFcv) is started. In the current flow the assignment happens before any read, so the defect is latent rather than an active read of an uninitialized value; however, the member is still left uninitialized by construction, which is fragile — any future path that reads _lastFcv before the assignment (e.g. a differently-ordered start, or a new construction site) would be undefined behavior.

      The enum defines sentinel values such as kInvalid and kUnsetDefaultLastLTSBehavior intended for exactly this "unset" state, but none is used as a default.

      Found by static analysis (Svace, UNINIT.CTOR): "Constructor may not initialize class members of 'mongo::ClusterServerParameterRefresher'. Following members aren't initialized: _lastFcv." (The originally flagged explicit ClusterServerParameterRefresher() = default; line has since been removed, but the underlying uninitialized member remains.)

      Suggested fix: give the member a default initializer, e.g. multiversion::FeatureCompatibilityVersion _lastFcv = multiversion::FeatureCompatibilityVersion::kInvalid;.

            Assignee:
            Kenan Ali
            Reporter:
            Павел N/A (EXT)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: