elf*_xlatetof: do not check ELF_T_NHDR[8] has integer number of records

Message ID 20240828214302.367437-1-mark@klomp.org
State Committed
Headers
Series elf*_xlatetof: do not check ELF_T_NHDR[8] has integer number of records |

Commit Message

Mark Wielaard Aug. 28, 2024, 9:43 p.m. UTC
  commit bc0f7450c "elf*_xlatetom: do not check ELF_T_NHDR has integer
number of records" fixed
https://bugzilla.redhat.com/show_bug.cgi?id=835877
But only for xlatetom. Do the same for xlatetof.

       * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Do not check for
       integer number of records in case of ELF_T_NHDR[8].

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libelf/elf32_xlatetof.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Mark Wielaard Sept. 11, 2024, 3:05 p.m. UTC | #1
Hi,

On Wed, 2024-08-28 at 23:43 +0200, Mark Wielaard wrote:
> commit bc0f7450c "elf*_xlatetom: do not check ELF_T_NHDR has integer
> number of records" fixed
> https://bugzilla.redhat.com/show_bug.cgi?id=835877
> But only for xlatetom. Do the same for xlatetof.
> 
>        * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Do not check for
>        integer number of records in case of ELF_T_NHDR[8].

Pushed this to main.

Cheers,

Mark
  

Patch

diff --git a/libelf/elf32_xlatetof.c b/libelf/elf32_xlatetof.c
index ab857409329a..ab3e609ee5d2 100644
--- a/libelf/elf32_xlatetof.c
+++ b/libelf/elf32_xlatetof.c
@@ -51,7 +51,11 @@  elfw2(LIBELFBITS, xlatetof) (Elf_Data *dest, const Elf_Data *src,
      data types are identical.  */
   size_t recsize = __libelf_type_sizes[ELFW(ELFCLASS,LIBELFBITS) - 1][src->d_type];
 
-  if (src->d_size % recsize != 0)
+  /* We shouldn't require integer number of records when processing
+     notes.  Payload bytes follow the header immediately, it's not an
+     array of records as is the case otherwise.  */
+  if (src->d_type != ELF_T_NHDR && src->d_type != ELF_T_NHDR8
+      && src->d_size % recsize != 0)
     {
       __libelf_seterrno (ELF_E_INVALID_DATA);
       return NULL;