Skip to content

Commit

Permalink
Type builder: keys from non-mutable base types
Browse files Browse the repository at this point in the history
This fixes a null pointer dereference in comparing key ids in dynamically constructing
a (de)serializer when the key is an inherited composite key in a non-mutable type, e.g.:

    @Final struct K { long a; };
    @Final struct Base { @key K a; };
    @Final struct Derived : Base { };

Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson committed Jun 18, 2024
1 parent 24c6e8c commit 545f4cb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/core/ddsi/src/ddsi_typebuilder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,15 +1500,19 @@ static int key_id_cmp (const void *va, const void *vb)
for (uint32_t n = 0; n < (*a)->path->n_parts; n++)
{
assert (n < (*b)->path->n_parts);
if ((*a)->path->parts[n].kind == KEY_PATH_PART_INHERIT_MUTABLE)
switch ((*a)->path->parts[n].kind)
{
/* a derived type cannot add keys, so all keys must have an INHERIT_MUTABLE
kind part at this index */
assert ((*b)->path->parts[n].kind == KEY_PATH_PART_INHERIT_MUTABLE);
continue;
case KEY_PATH_PART_INHERIT:
case KEY_PATH_PART_INHERIT_MUTABLE:
/* a derived type cannot add keys, so all keys must have an INHERIT_MUTABLE
kind part at this index */
assert ((*b)->path->parts[n].kind == (*a)->path->parts[n].kind);
break;
case KEY_PATH_PART_REGULAR:
if ((*a)->path->parts[n].member->member_id != (*b)->path->parts[n].member->member_id)
return (*a)->path->parts[n].member->member_id < (*b)->path->parts[n].member->member_id ? -1 : 1;
break;
}
if ((*a)->path->parts[n].member->member_id != (*b)->path->parts[n].member->member_id)
return (*a)->path->parts[n].member->member_id < (*b)->path->parts[n].member->member_id ? -1 : 1;
}
assert ((*a)->path->n_parts == (*b)->path->n_parts);
return 0;
Expand Down

0 comments on commit 545f4cb

Please sign in to comment.