public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* asan: Buffer overflow in som_set_reloc_info
@ 2022-03-17 11:00 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-03-17 11:00 UTC (permalink / raw)
  To: binutils

	* som.c (som_set_reloc_info): Add symcount parameter.  Don't
	access symbols past symcount.  Don't access fixup past end_fixups.
	(som_slurp_reloc_table): Adjust som_set_reloc_info calls.

diff --git a/bfd/som.c b/bfd/som.c
index d53a3b90b02..3c0b68a444e 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -4939,6 +4939,7 @@ som_set_reloc_info (unsigned char *fixup,
 		    arelent *internal_relocs,
 		    asection *section,
 		    asymbol **symbols,
+		    unsigned int symcount,
 		    bool just_count)
 {
   unsigned int op, varname, deallocate_contents = 0;
@@ -5032,7 +5033,7 @@ som_set_reloc_info (unsigned char *fixup,
 	      else if (ISLOWER (c))
 		{
 		  int bits = (c - 'a') * 8;
-		  for (v = 0; c > 'a'; --c)
+		  for (v = 0; c > 'a' && fixup < end_fixups; --c)
 		    v = (v << 8) | *fixup++;
 		  if (varname == 'V')
 		    v = sign_extend (v, bits);
@@ -5093,7 +5094,7 @@ som_set_reloc_info (unsigned char *fixup,
 	    /* A symbol to use in the relocation.  Make a note
 	       of this if we are not just counting.  */
 	    case 'S':
-	      if (! just_count)
+	      if (! just_count && (unsigned int) c < symcount)
 		rptr->sym_ptr_ptr = &symbols[c];
 	      break;
 	    /* Argument relocation bits for a function call.  */
@@ -5309,7 +5310,7 @@ som_slurp_reloc_table (bfd *abfd,
 	 need it again.  */
       section->reloc_count = som_set_reloc_info (external_relocs,
 						 fixup_stream_size,
-						 NULL, NULL, NULL, true);
+						 NULL, NULL, NULL, 0, true);
 
       som_section_data (section)->reloc_stream = external_relocs;
     }
@@ -5335,7 +5336,8 @@ som_slurp_reloc_table (bfd *abfd,
 
   /* Process and internalize the relocations.  */
   som_set_reloc_info (external_relocs, fixup_stream_size,
-		      internal_relocs, section, symbols, false);
+		      internal_relocs, section, symbols,
+		      bfd_get_symcount (abfd), false);
 
   /* We're done with the external relocations.  Free them.  */
   free (external_relocs);

-- 
Alan Modra
Australia Development Lab, IBM

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

only message in thread, other threads:[~2022-03-17 11:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17 11:00 asan: Buffer overflow in som_set_reloc_info 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).