]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Check correct ELF header size
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 15 Feb 2025 21:03:34 +0000 (22:03 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 18 Feb 2025 21:45:12 +0000 (15:45 -0600)
Check if enough bytes are available for Elf32_Ehdr, not Elf32_Shdr.
The size of Elf32_Shdr is needed later on.

Since both are 64 bytes, no functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/279
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-elf.c

index 30388bc1ecea4a397645d6f8161605c6d5a8dfa4..f215f1ee0020f89751ecb42ce245d1731c44c603 100644 (file)
@@ -349,14 +349,14 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size)
                Elf32_Ehdr *hdr;
 
                shdr_size = sizeof(Elf32_Shdr);
-               if (!elf_range_valid(elf, 0, shdr_size))
+               if (!elf_range_valid(elf, 0, sizeof(*hdr)))
                        goto invalid;
                LOAD_HEADER;
        } else {
                Elf64_Ehdr *hdr;
 
                shdr_size = sizeof(Elf64_Shdr);
-               if (!elf_range_valid(elf, 0, shdr_size))
+               if (!elf_range_valid(elf, 0, sizeof(*hdr)))
                        goto invalid;
                LOAD_HEADER;
        }