Skip to content

Please check the code that might have a problem. #5680

@jasonhcchen

Description

@jasonhcchen

https://github.com/FreeRADIUS/freeradius-server/blob/12206ed6bc2114679a2c88ead602ccb96efc0fe2/src/lib/util/hash.c#L217C3-L217C23

The following line might be problematic:
last = &(cur->next);
If the program goes to the following line and if the statement is true:
if (cmp > 0) break;
The new node cannot be inserted in the correct position.

static bool list_insert(fr_hash_table_t *ht, fr_hash_entry_t **head, fr_hash_entry_t *node)
{
fr_hash_entry_t **last, *cur;

last = head;

for (cur = *head; cur != &ht->null; cur = cur->next) {
	if (cur->reversed > node->reversed) break;
	last = &(cur->next);

	if (cur->reversed == node->reversed) {
		if (ht->cmp) {
			int8_t cmp = ht->cmp(node->data, cur->data);
			if (cmp > 0) break;
			if (cmp < 0) continue;
		}
		return false;
	}
}

node->next = *last;
*last = node;

return true;

}

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