diff options
| author | Heather McIntyre <[email protected]> | 2024-07-12 18:32:34 -0400 |
|---|---|---|
| committer | Aaron Merey <[email protected]> | 2024-08-20 17:13:01 -0400 |
| commit | 97b72c00603d1221c69ed22a8345817dde1685f3 (patch) | |
| tree | a841bea45787a80fcd3fb2bd2fcfc3a93979e56c /libelf | |
| parent | f3de289b5081bdcea6f867f1d87f006daf5a02ce (diff) | |
libelf: Fix deadlock in elf_cntl
* libelf/elf_cntl.c (elf_cntl): Move rwlock_wrlock, rwlock_unlock,
inside case switch statements. Remove unnecessary early return.
Signed-off-by: Heather S. McIntyre <[email protected]>
Signed-off-by: Aaron Merey <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libelf')
| -rw-r--r-- | libelf/elf_cntl.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/libelf/elf_cntl.c b/libelf/elf_cntl.c index 04aa9132..da4ea999 100644 --- a/libelf/elf_cntl.c +++ b/libelf/elf_cntl.c @@ -42,19 +42,11 @@ elf_cntl (Elf *elf, Elf_Cmd cmd) if (elf == NULL) return -1; - if (elf->fildes == -1) - { - __libelf_seterrno (ELF_E_INVALID_HANDLE); - return -1; - } - - rwlock_wrlock (elf->lock); - switch (cmd) { case ELF_C_FDREAD: /* If not all of the file is in the memory read it now. */ - if (elf->map_address == NULL && __libelf_readall (elf) == NULL) + if (__libelf_readall (elf) == NULL) { /* We were not able to read everything. */ result = -1; @@ -64,7 +56,9 @@ elf_cntl (Elf *elf, Elf_Cmd cmd) case ELF_C_FDDONE: /* Mark the file descriptor as not usable. */ + rwlock_wrlock (elf->lock); elf->fildes = -1; + rwlock_unlock (elf->lock); break; default: @@ -73,7 +67,5 @@ elf_cntl (Elf *elf, Elf_Cmd cmd) break; } - rwlock_unlock (elf->lock); - return result; } |
