summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2023-09-07 16:14:43 +0200
committerMark Wielaard <[email protected]>2023-09-11 09:39:39 +0200
commitd0525debab65a3a4a35c292052f8706b90635911 (patch)
tree97f8c05ffaaa6114eb68efef59e8145db958d9f1
parent549c1d4ba0046f77fecca7891da82a3c6718c102 (diff)
libelf: tdelete dummy key if anything goes wrong setting up rawchunk
elf_getdata_rawchunk uses a binary search tree cache. If a rawchunk is not yet in the cache we setup a new entry. But if anything went wrong setting up the new rawchunk we would leave a NULL key in the cache. This could blow up the next search. Fix this by removing the (dummy) key from the cache on any failure. * libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk): Don't assign NULL to *found. Call tdelete if anything goes wrong. Signed-off-by: Mark Wielaard <[email protected]>
-rw-r--r--libelf/elf_getdata_rawchunk.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libelf/elf_getdata_rawchunk.c b/libelf/elf_getdata_rawchunk.c
index cfd40396..05ff329c 100644
--- a/libelf/elf_getdata_rawchunk.c
+++ b/libelf/elf_getdata_rawchunk.c
@@ -107,8 +107,10 @@ elf_getdata_rawchunk (Elf *elf, int64_t offset, size_t size, Elf_Type type)
goto out;
}
- /* New entry. */
- *found = NULL;
+ /* New entry. Note that *found will point to the newly inserted
+ (dummy) key. We'll replace it with a real rawchunk when that is
+ setup. Make sure to tdelete the dummy key if anything goes
+ wrong. */
size_t align = __libelf_type_align (elf->class, type);
if (elf->map_address != NULL)
@@ -134,6 +136,7 @@ elf_getdata_rawchunk (Elf *elf, int64_t offset, size_t size, Elf_Type type)
if (rawchunk == NULL)
{
nomem:
+ tdelete (&key, &elf->state.elf.rawchunks, &chunk_compare);
__libelf_seterrno (ELF_E_NOMEM);
goto out;
}
@@ -144,6 +147,7 @@ elf_getdata_rawchunk (Elf *elf, int64_t offset, size_t size, Elf_Type type)
!= size))
{
/* Something went wrong. */
+ tdelete (&key, &elf->state.elf.rawchunks, &chunk_compare);
free (rawchunk);
__libelf_seterrno (ELF_E_READ_ERROR);
goto out;