aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2019-06-26 17:03:32 +0100
committerNick Clifton <nickc@redhat.com>2019-06-26 17:03:32 +0100
commita68aa5d3020948564ef99d704d27e458ba22ad9d (patch)
treee413d62d4438b6a7605e7771c0028d89eba01e97
parent762c164d754fc456aa4764d2ed19cc4a3ec625fb (diff)
downloadgdb-a68aa5d3020948564ef99d704d27e458ba22ad9d.zip
gdb-a68aa5d3020948564ef99d704d27e458ba22ad9d.tar.gz
gdb-a68aa5d3020948564ef99d704d27e458ba22ad9d.tar.bz2
Ensure that when attempting to process an ARM Mach-O file with unknown relocs, that a suitable error message is displayed.
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.
-rw-r--r--bfd/ChangeLog8
-rw-r--r--bfd/mach-o-arm.c22
-rw-r--r--bfd/mach-o.c13
-rw-r--r--binutils/ChangeLog7
-rw-r--r--binutils/bucomm.c12
5 files changed, 57 insertions, 5 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 0783242..0e1847e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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
diff --git a/bfd/mach-o-arm.c b/bfd/mach-o-arm.c
index 2c14740..2a25d70 100644
--- a/bfd/mach-o-arm.c
+++ b/bfd/mach-o-arm.c
@@ -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;
}
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index d9edef2..4e64086 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -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;
}
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 63822e4..07c8bb6 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -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
diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index 558ee2f..21adb05 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -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);