Skip to content

Please review a risky code that a node might be inaccessible after replacement of data. #5681

@jasonhcchen

Description

@jasonhcchen

node->data = UNCONST(void *, data);

In the following code:
node->data = UNCONST(void *, data);

Old data is replaced by the new data if the node is found in hash_table_find(). But we're not sure if ht->hash(data) is identical to ht->hash(node->data). If not, the updated node cannot be found again...

int fr_hash_table_replace(void **old, fr_hash_table_t *ht, void const *data)
{
fr_hash_entry_t *node;

node = hash_table_find(ht, ht->hash(data), data);
if (!node) {
	if (old) *old = NULL;
	return fr_hash_table_insert(ht, data) ? 1 : -1;
}

if (old) {
	*old = node->data;
} else if (ht->free) {
	ht->free(node->data);
}

node->data = UNCONST(void *, data);

return 0;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions