-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Not Applicable
-
Storage Engines
-
5
-
StorEng - Defined Pipeline
Motivated by this comment in WT-13166.
We often cast a WT_CURSOR cursor to one of it's implementations (WT_CURSOR_HS, WT_CURSOR_BTREE, etc) with a direct cast, however we don't perform any sanity checks that we are converting to the correct type. If we convert a WT_CURSOR_HS to a WT_CURSOR_BTREE instead we'll read invalid data from the structure, or possibly data beyond the end of the struct.
This ticket is to add a new field WT_CURSOR::cursor_type to the WT_CURSOR interface so we can validate during type casting that we're casting to the correct type. This field should be HAVE_DIAGNOSTIC only and not exposed in the public API.
The end result is that existing casts
c = (WT_CURSOR_BTREE*) cursor;
will perform correctness checks
c = CUR_2_CURBT(cursor);
// A possible implementation using the comma operator
#define CUR_2_CURBT(cursor) (WT_ASSERT(cursor->cursor_type == WT_CURSOR_TYPE_BTREE), (WT_CURSOR_BTREE*) cursor)