core: Zero out unused entries when extending ptr_table array in ptr_table__add()

Otherwise we may end up accessing invalid pointers and crashing.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-07-16 20:17:02 -03:00
parent d133569bd0
commit 5a85d9a450
1 changed files with 4 additions and 0 deletions

View File

@ -452,6 +452,10 @@ static int ptr_table__add(struct ptr_table *pt, void *ptr, uint32_t *idxp)
if (entries == NULL)
return -ENOMEM;
/* Zero out the new range */
memset(entries + pt->allocated_entries * sizeof(void *), 0,
(allocated_entries - pt->allocated_entries) * sizeof(void *));
pt->allocated_entries = allocated_entries;
pt->entries = entries;
}