db_tutorial icon indicating copy to clipboard operation
db_tutorial copied to clipboard

bug report

Open RFoe opened this issue 8 months ago • 1 comments

Atempt to get the rightmost child without validation

Issue

In db.c : create_new_root(...)

code:

  if (get_node_type(left_child) == NODE_INTERNAL) {
    void* child;
    for (int i = 0; i < *internal_node_num_keys(left_child); i++) {
      child = get_page(table->pager, *internal_node_child(left_child,i));
      *node_parent(child) = left_child_page_num;
    }
    child = get_page(table->pager, *internal_node_right_child(left_child)); // POTENTIAL ERROR HERE
    *node_parent(child) = left_child_page_num;
  }

RFoe avatar Mar 30 '25 12:03 RFoe

The bug here is caused by not validating the rightmost child pointer in create_new_root(...) before dereferencing it: child = get_page(table->pager, *internal_node_right_child(left_child)); // POTENTIAL ERROR *node_parent(child) = left_child_page_num; If the right child is missing or its pointer is invalid, this can cause segmentation faults or corrupt the B-tree structure. To fix, add validation for the right child pointer before calling get_page and updating its parent. This will make root splits safer and more robust in all edge cases.

0xVENOM-DDOS avatar Aug 31 '25 13:08 0xVENOM-DDOS