Ensure that when attempting to process an ARM Mach-O file with unknown relocs, that...
authorNick Clifton <nickc@redhat.com>
Wed, 26 Jun 2019 16:03:32 +0000 (17:03 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 26 Jun 2019 16:03:32 +0000 (17:03 +0100)
PR 24703
binutils* bucomm.c (bfd_nonfatal): If no bfd error code has been set then
indicate this in the output.
(bfd_nonfatal_message): Likewise.

bfd * mach-o-arm.c (bfd_mach_o_arm_canonicalize_one_reloc): Add error
messages for failures.
* mach-o.c (bfd_mach_o_canonicalize_relocs): Set an bfd error code
if returning an error value.

bfd/ChangeLog
bfd/mach-o-arm.c
bfd/mach-o.c
binutils/ChangeLog
binutils/bucomm.c

index 0783242758acdaad7e27e00bbdbef0869fac9513..0e1847e6e7ff0d400700b1aff062fb66057dbf82 100644 (file)
@@ -1,3 +1,11 @@
+2019-06-26  Nick Clifton  <nickc@redhat.com>
+
+       PR 24703
+       * mach-o-arm.c (bfd_mach_o_arm_canonicalize_one_reloc): Add error
+       messages for failures.
+       * mach-o.c (bfd_mach_o_canonicalize_relocs): Set an bfd error code
+       if returning an error value.
+
 2019-06-25  Jan Beulich  <jbeulich@suse.com>
 
        * elf-properties.c (elf_find_and_remove_property): Rename last
index 2c147403d1dbee72aa81c4c6a5bd784106898208..2a25d703eeddb93f632461730a872bcde5f37dec 100644 (file)
@@ -156,7 +156,10 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
   bfd_mach_o_reloc_info reloc;
 
   if (!bfd_mach_o_pre_canonicalize_one_reloc (abfd, raw, &reloc, res, syms))
+    {
+fprintf (stderr, "ARm 1\n");
     return FALSE;
+    }
 
   if (reloc.r_scattered)
     {
@@ -165,7 +168,11 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
        case BFD_MACH_O_ARM_RELOC_PAIR:
          /* PR 21813: Check for a corrupt PAIR reloc at the start.  */
          if (res == res_base)
+           {
+             _bfd_error_handler (_("\
+malformed mach-o ARM reloc pair: reloc is first reloc"));
            return FALSE;
+           }
          if (reloc.r_length == 2)
            {
              res->howto = &arm_howto_table[7];
@@ -178,6 +185,8 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
              res->address = res[-1].address;
              return TRUE;
            }
+         _bfd_error_handler (_("\
+malformed mach-o ARM reloc pair: invalid length: %d"), reloc.r_length);
          return FALSE;
 
        case BFD_MACH_O_ARM_RELOC_SECTDIFF:
@@ -191,6 +200,8 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
              res->howto = &arm_howto_table[8];
              return TRUE;
            }
+         _bfd_error_handler (_("\
+malformed mach-o ARM sectdiff reloc: invalid length: %d"), reloc.r_length);
          return FALSE;
 
        case BFD_MACH_O_ARM_RELOC_LOCAL_SECTDIFF:
@@ -204,6 +215,9 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
              res->howto = &arm_howto_table[9];
              return TRUE;
            }
+         _bfd_error_handler (_("\
+malformed mach-o ARM local sectdiff reloc: invalid length: %d"),
+                             reloc.r_length);
          return FALSE;
 
        case BFD_MACH_O_ARM_RELOC_HALF_SECTDIFF:
@@ -216,6 +230,9 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
              res->howto = &arm_howto_table[14];
              return TRUE;
            }
+         _bfd_error_handler (_("\
+malformed mach-o ARM half sectdiff reloc: invalid length: %d"),
+                             reloc.r_length);
          return FALSE;
 
        default:
@@ -245,6 +262,9 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
              res->howto = &arm_howto_table[3];
              return TRUE;
            default:
+             _bfd_error_handler (_("\
+malformed mach-o ARM vanilla reloc: invalid length: %d (pcrel: %d)"),
+                                 reloc.r_length, reloc.r_pcrel);
              return FALSE;
            }
          break;
@@ -306,6 +326,8 @@ bfd_mach_o_arm_canonicalize_one_reloc (bfd *       abfd,
        }
     }
 
+  _bfd_error_handler (_("\
+malformed mach-o ARM reloc: unknown reloc type: %d"), reloc.r_length);
   return FALSE;
 }
 
index d9edef2871d83b53280b613935c068e4327f3270..4e6408670dd7c1dfe2f2f59671934324bd79cd26 100644 (file)
@@ -1501,7 +1501,11 @@ bfd_mach_o_canonicalize_non_scattered_reloc (bfd *abfd,
     {
       /* PR 17512: file: 006-2964-0.004.  */
       if (num > mdata->nsects)
-       return FALSE;
+       {
+         _bfd_error_handler (_("\
+malformed mach-o reloc: section index is greater than the number of sections"));
+         return FALSE;
+       }
 
       /* A section number.  */
       sym = mdata->sections[num - 1]->bfdsection->symbol_ptr_ptr;
@@ -1609,7 +1613,7 @@ bfd_mach_o_canonicalize_relocs (bfd *abfd, unsigned long filepos,
 {
   bfd_mach_o_backend_data *bed = bfd_mach_o_get_backend_data (abfd);
   unsigned long i;
-  struct mach_o_reloc_info_external *native_relocs;
+  struct mach_o_reloc_info_external *native_relocs = NULL;
   bfd_size_type native_size;
 
   /* Allocate and read relocs.  */
@@ -1617,7 +1621,7 @@ bfd_mach_o_canonicalize_relocs (bfd *abfd, unsigned long filepos,
 
   /* PR 17512: file: 09477b57.  */
   if (native_size < count)
-    return -1;
+    goto err;
 
   native_relocs =
     (struct mach_o_reloc_info_external *) bfd_malloc (native_size);
@@ -1636,8 +1640,11 @@ bfd_mach_o_canonicalize_relocs (bfd *abfd, unsigned long filepos,
     }
   free (native_relocs);
   return i;
+
  err:
   free (native_relocs);
+  if (bfd_get_error () == bfd_error_no_error)
+    bfd_set_error (bfd_error_invalid_operation);
   return -1;
 }
 
index 63822e40a9d577e5b88fab11789815b1f11b1765..07c8bb69d2af7bf6d53ed96d08ff525a51a1d915 100644 (file)
@@ -1,3 +1,10 @@
+2019-06-26  Nick Clifton  <nickc@redhat.com>
+
+       PR 24703
+       * bucomm.c (bfd_nonfatal): If no bfd error code has been set then
+       indicate this in the output.
+       (bfd_nonfatal_message): Likewise.
+
 2019-06-25  Jan Beulich  <jbeulich@suse.com>
 
        * readelf.c (dump_ctf_indent_lines): Rename local variable
index 558ee2ffb731188a9c2d69ae068ed16f628a5e7b..21adb05c4188556de5273df9088c9dc6d4b3fc8b 100644 (file)
@@ -44,8 +44,12 @@ void
 bfd_nonfatal (const char *string)
 {
   const char *errmsg;
+  enum bfd_error err = bfd_get_error ();
 
-  errmsg = bfd_errmsg (bfd_get_error ());
+  if (err == bfd_error_no_error)
+    errmsg = _("cause of error unknown");
+  else
+    errmsg = bfd_errmsg (err);
   fflush (stdout);
   if (string)
     fprintf (stderr, "%s: %s: %s\n", program_name, string, errmsg);
@@ -74,8 +78,12 @@ bfd_nonfatal_message (const char *filename,
   const char *errmsg;
   const char *section_name;
   va_list args;
+  enum bfd_error err = bfd_get_error ();
 
-  errmsg = bfd_errmsg (bfd_get_error ());
+  if (err == bfd_error_no_error)
+    errmsg = _("cause of error unknown");
+  else
+    errmsg = bfd_errmsg (err);
   fflush (stdout);
   section_name = NULL;
   va_start (args, format);
This page took 0.029592 seconds and 4 git commands to generate.