Create macro for safe casting of dhandles

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: DHandles
    • None
    • Storage Engines, Storage Engines - Foundations
    • None
    • None

      One of the problems fixed by WT-15835 was casting session->dhandle to a WT_LAYERED * (and it wasn't one of those).  ivan.kochin@mongodb.com advocated for a way to catch more of this kind of error.

      Perhaps before we cast session->dhandle we should check:

          WT_ASSERT_ALWAYS(session, session->dhandle->type == WT_DHANDLE_TYPE_LAYERED)

       Even better would be a new macro.  We already have S2BT, so maybe something like:

        layered = S2LAYERED(session);

      Might as well add:

        table = S2TABLE(session);

      where table is a WT_TABLE*. These could encapsulate the assert while doing the cast.  (Probably good to put the assert into S2BT, at least for diagnostic builds).  To encapsulate an assert and return a value as well, S2LAYERED, etc. may actually have to be inline functions, or be a macro that calls a helper inline function.

      These should be used within WT where we do raw casts of session->dhandle.  With this, WT-15738 could have been caught in a more straightforward way (rather than being lucky with a detected heap overflow).

      Part of this ticket should be to audit WT source and use the new macro for WT_LAYERED casts.  Optional to look at all dhandle casts, or push that to another ticket.

            Assignee:
            [DO NOT USE] Backlog - Storage Engines Team
            Reporter:
            Donald Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: