return flag;
}
+/* HOWTO describes a relocation, at offset OCTET. Return whether the
+ relocation field is within SECTION of ABFD. */
+
+static bfd_boolean
+reloc_offset_in_range (reloc_howto_type *howto, bfd *abfd,
+ asection *section, bfd_size_type octet)
+{
+ bfd_size_type octet_end = bfd_get_section_limit_octets (abfd, section);
+ bfd_size_type reloc_size = bfd_get_reloc_size (howto);
+
+ /* The reloc field must be contained entirely within the section.
+ Allow zero length fields (marker relocs or NONE relocs where no
+ relocation will be performed) at the end of the section. */
+ return octet <= octet_end && octet + reloc_size <= octet_end;
+}
+
/*
FUNCTION
bfd_perform_relocation
if (howto == NULL)
return bfd_reloc_undefined;
- /* Is the address of the relocation really within the section?
- Include the size of the reloc in the test for out of range addresses.
- PR 17512: file: c146ab8b, 46dff27f, 38e53ebf. */
+ /* Is the address of the relocation really within the section? */
octets = reloc_entry->address * bfd_octets_per_byte (abfd);
- if (octets + bfd_get_reloc_size (howto)
- > bfd_get_section_limit_octets (abfd, input_section)
- /* Check for an overly large offset which
- masquerades as a negative value too. */
- || (octets + bfd_get_reloc_size (howto) < bfd_get_reloc_size (howto)))
+ if (!reloc_offset_in_range (howto, abfd, input_section, octets))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
/* Is the address of the relocation really within the section? */
octets = reloc_entry->address * bfd_octets_per_byte (abfd);
- if (octets + bfd_get_reloc_size (howto)
- > bfd_get_section_limit_octets (abfd, input_section))
+ if (!reloc_offset_in_range (howto, abfd, input_section, octets))
return bfd_reloc_outofrange;
/* Work out which section the relocation is targeted at and the
bfd_size_type octets = address * bfd_octets_per_byte (input_bfd);
/* Sanity check the address. */
- if (octets + bfd_get_reloc_size (howto)
- > bfd_get_section_limit_octets (input_bfd, input_section))
+ if (!reloc_offset_in_range (howto, input_bfd, input_section, octets))
return bfd_reloc_outofrange;
/* This function assumes that we are dealing with a basic relocation