Skip to content

Commit f217207

Browse files
committed
elfedit: segv with --enable-x86-feature
PR 33024 PR 33025 * elfedit.c (update_gnu_property): Sanity check program headers.
1 parent ee623fd commit f217207

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

binutils/elfedit.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ update_gnu_property (const char *file_name, FILE *file)
105105
if (map == MAP_FAILED)
106106
{
107107
error (_("%s: mmap () failed\n"), file_name);
108-
return 0;
108+
return 1;
109+
}
110+
111+
if ((elf_header.e_ident[EI_CLASS] == ELFCLASS32
112+
? sizeof (Elf32_External_Phdr)
113+
: sizeof (Elf64_External_Phdr)) != elf_header.e_phentsize
114+
|| elf_header.e_phoff > (size_t) st_buf.st_size
115+
|| (elf_header.e_phnum * (size_t) elf_header.e_phentsize
116+
> st_buf.st_size - elf_header.e_phoff))
117+
{
118+
error (_("%s: can't read program headers\n"), file_name);
119+
return 1;
109120
}
110121

111122
phdrs = xmalloc (elf_header.e_phnum * sizeof (*phdrs));

0 commit comments

Comments
 (0)