typedef struct
{
- const char * section_name;
+ char section_name[SCNNMLEN];
unsigned long must_have;
}
pe_required_section_flags;
{ ".text" , IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE },
{ ".tls", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_WRITE },
{ ".xdata", IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA },
- { NULL, 0}
};
pe_required_section_flags * p;
by ld --enable-auto-import (if auto-import is actually needed),
by ld --omagic, or by obcopy --writable-text. */
- for (p = known_sections; p->section_name; p++)
- if (strcmp (scnhdr_int->s_name, p->section_name) == 0)
+ for (p = known_sections;
+ p < known_sections + ARRAY_SIZE (known_sections);
+ p++)
+ if (memcmp (scnhdr_int->s_name, p->section_name, SCNNMLEN) == 0)
{
- if (strcmp (scnhdr_int->s_name, ".text")
+ if (memcmp (scnhdr_int->s_name, ".text", sizeof ".text")
|| (bfd_get_file_flags (abfd) & WP_TEXT))
scnhdr_int->s_flags &= ~IMAGE_SCN_MEM_WRITE;
scnhdr_int->s_flags |= p->must_have;
if (coff_data (abfd)->link_info
&& ! bfd_link_relocatable (coff_data (abfd)->link_info)
&& ! bfd_link_pic (coff_data (abfd)->link_info)
- && strcmp (scnhdr_int->s_name, ".text") == 0)
+ && memcmp (scnhdr_int->s_name, ".text", sizeof ".text") == 0)
{
/* By inference from looking at MS output, the 32 bit field
which is the combination of the number_of_relocs and
if (hint_addr == 0)
hint_addr = first_thunk;
- if (hint_addr != 0)
+ if (hint_addr != 0 && hint_addr - adj < datasize)
{
bfd_byte *ft_data;
asection *ft_section;
dataoff = addr - section->vma;
datasize = extra->DataDirectory[PE_EXPORT_TABLE].Size;
- if (datasize > section->size - dataoff)
+ if (dataoff > section->size
+ || datasize > section->size - dataoff)
{
fprintf (file,
_("\nThere is an export table in %s, but it does not fit into that section\n"),
}
/* PR 17512: Handle corrupt PE binaries. */
- if (datasize < 36)
+ if (datasize < 40)
{
fprintf (file,
/* xgettext:c-format */
edt.base);
/* PR 17512: Handle corrupt PE binaries. */
- if (edt.eat_addr + (edt.num_functions * 4) - adj >= datasize
+ /* PR 17512 file: 140-165018-0.004. */
+ if (edt.eat_addr - adj >= datasize
/* PR 17512: file: 092b1829 */
- || (edt.num_functions * 4) < edt.num_functions
- /* PR 17512 file: 140-165018-0.004. */
- || data + edt.eat_addr - adj < data)
+ || (edt.num_functions + 1) * 4 < edt.num_functions
+ || edt.eat_addr - adj + (edt.num_functions + 1) * 4 > datasize)
fprintf (file, _("\tInvalid Export Address Table rva (0x%lx) or entry count (0x%lx)\n"),
(long) edt.eat_addr,
(long) edt.num_functions);
if ((stop % onaline) != 0)
fprintf (file,
/* xgettext:c-format */
- _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),
+ _("warning, .pdata section size (%ld) is not a multiple of %d\n"),
(long) stop, onaline);
fprintf (file,
if ((stop % onaline) != 0)
fprintf (file,
/* xgettext:c-format */
- _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),
+ _("warning, .pdata section size (%ld) is not a multiple of %d\n"),
(long) stop, onaline);
fprintf (file,
(uint64_t) (section->size - (addr - section->vma)));
return FALSE;
}
+ /* PR 23110. */
+ else if (ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size < 0)
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler
+ (_("%pB: Data Directory size (%#lx) is negative"),
+ obfd, ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size);
+ return FALSE;
+ }
for (i = 0; i < ope->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
/ sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
if (!bfd_set_section_contents (obfd, section, data, 0, section->size))
{
- _bfd_error_handler (_("Failed to update file offsets in debug directory"));
+ _bfd_error_handler (_("failed to update file offsets in debug directory"));
return FALSE;
}
}
else if (section)
{
- _bfd_error_handler (_("%pB: Failed to read debug data section"), obfd);
+ _bfd_error_handler (_("%pB: failed to read debug data section"), obfd);
return FALSE;
}
}
if (adir->characteristics != bdir->characteristics)
{
- _bfd_error_handler (_(".rsrc merge failure: dirs with differing characteristics\n"));
+ _bfd_error_handler (_(".rsrc merge failure: dirs with differing characteristics"));
bfd_set_error (bfd_error_file_truncated);
return;
}
if (adir->major != bdir->major || adir->minor != bdir->minor)
{
- _bfd_error_handler (_(".rsrc merge failure: differing directory versions\n"));
+ _bfd_error_handler (_(".rsrc merge failure: differing directory versions"));
bfd_set_error (bfd_error_file_truncated);
return;
}