public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* bfin reloc offset checks
@ 2022-06-08 12:01 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-06-08 12:01 UTC (permalink / raw)
  To: binutils

These all ought to use bfd_reloc_offset_in_range.  In particular, replace
the check using howto->size + 1u.

	* elf32-bfin.c (bfin_pcrel24_reloc): Use bfd_reloc_offset_in_range.
	(bfin_imm16_reloc, bfin_byte4_reloc, bfin_bfd_reloc),
	(bfin_final_link_relocate): Likewise.

diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index b41c212c2ba..babc57e3955 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -59,9 +59,8 @@ bfin_pcrel24_reloc (bfd *abfd,
   reloc_howto_type *howto = reloc_entry->howto;
   asection *output_section;
   bool relocatable = (output_bfd != NULL);
-  bfd_size_type limit = bfd_get_section_limit_octets (abfd, input_section);
 
-  if (addr - 2 > limit || limit - (addr - 2) < 2)
+  if (!bfd_reloc_offset_in_range (howto, abfd, input_section, addr - 2))
     return bfd_reloc_outofrange;
 
   if (bfd_is_und_section (symbol->section)
@@ -157,10 +156,9 @@ bfin_imm16_reloc (bfd *abfd,
   reloc_howto_type *howto = reloc_entry->howto;
   asection *output_section;
   bool relocatable = (output_bfd != NULL);
-  bfd_size_type limit = bfd_get_section_limit_octets (abfd, input_section);
 
   /* Is the address of the relocation really within the section?  */
-  if (reloc_addr > limit || limit - reloc_addr < 2)
+  if (!bfd_reloc_offset_in_range (howto, abfd, input_section, reloc_addr))
     return bfd_reloc_outofrange;
 
   if (bfd_is_und_section (symbol->section)
@@ -229,10 +227,10 @@ bfin_byte4_reloc (bfd *abfd,
   bfd_vma output_base = 0;
   asection *output_section;
   bool relocatable = (output_bfd != NULL);
-  bfd_size_type limit = bfd_get_section_limit_octets (abfd, input_section);
 
   /* Is the address of the relocation really within the section?  */
-  if (addr > limit || limit - addr < 4)
+  if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, input_section,
+				  addr))
     return bfd_reloc_outofrange;
 
   if (bfd_is_und_section (symbol->section)
@@ -297,10 +295,9 @@ bfin_bfd_reloc (bfd *abfd,
   reloc_howto_type *howto = reloc_entry->howto;
   asection *output_section;
   bool relocatable = (output_bfd != NULL);
-  bfd_size_type limit = bfd_get_section_limit_octets (abfd, input_section);
 
   /* Is the address of the relocation really within the section?  */
-  if (addr > limit || limit - addr < howto->size + 1u)
+  if (!bfd_reloc_offset_in_range (howto, abfd, input_section, addr))
     return bfd_reloc_outofrange;
 
   if (bfd_is_und_section (symbol->section)
@@ -1320,11 +1317,10 @@ bfin_final_link_relocate (Elf_Internal_Rela *rel, reloc_howto_type *howto,
     {
       bfd_reloc_status_type r = bfd_reloc_ok;
       bfd_vma x;
-      bfd_size_type limit = bfd_get_section_limit_octets (input_bfd,
-							  input_section);
 
-      if (address - 2 > limit || limit - (address - 2) < 4)
-	return bfd_reloc_outofrange;
+      if (!bfd_reloc_offset_in_range (howto, input_bfd, input_section,
+				      address - 2))
+	  return bfd_reloc_outofrange;
 
       value += addend;
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:01 bfin reloc offset checks Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).