Skip to content

e4c_store_mem: examine O(n) key lookup algorithm and examine if we need to a hash map if size is massive #13

@odeke-em

Description

@odeke-em

Just noticed while auditing the code

libe4/src/e4c_store_mem.c

Lines 84 to 104 in 601fd4d

int e4c_getindex(e4storage *store, const char *topic)
{
int i;
uint8_t hash[E4_TOPICHASH_LEN];
/* hash the topic */
if (e4c_derive_topichash(hash, E4_TOPICHASH_LEN, topic) != 0) {
return E4_ERROR_PERSISTENCE_ERROR;
}
/* look for it */
for (i = 0; i < store->topiccount; i++)
{
if (memcmp(store->topics[i].topic, hash, E4_TOPICHASH_LEN) == 0)
{
break;
}
}
if (i >= store->topiccount) return E4_ERROR_TOPICKEY_MISSING;
return i;
}

but we don't have an explanation on the number of keys that can be stored in e4store. What's going to be the usual size? How often will it be called? Would be nice to have an idea about this and add a comment if the number of keys will be very small but if lots we need to audit this code and profile it as it could definitely become an attack vector to issue worst case algorithmic complexity attacks.

Metadata

Metadata

Assignees

Labels

A-StorageRelated to key storage infrastructureO-LinuxLinuxP-LOWLow priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions