bfd_stat_arch_elt buffer overflow
authorAlan Modra <amodra@gmail.com>
Thu, 27 Feb 2020 03:20:21 +0000 (13:50 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 27 Feb 2020 06:34:55 +0000 (17:04 +1030)
If you manage to put an xcoff object file into a non-xcoff archive
(created by first putting a non-xcoff object file into it), and have
xcoff support compiled into libbfd, then objdump -x on the archive
can segfault.  The problem is that _bfd_xcoff_stat_arch_elt expects
abfd->arelt_data->arch_header to be one of the xcoff variants, but
arelt_data is generated depending on the archive format, *not* the
element format.

* bfd.c (bfd_stat_arch_elt): Use vector of containing archive,
if file is an archive element.
* bfd-in2.h: Regenerate.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/bfd.c

index f0b7a4a238e00009299d564a86b3b7df0146bdcc..ff03baa0dca1c735e8946f3af6103fc9bae76e90 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-27  Alan Modra  <amodra@gmail.com>
+
+       * bfd.c (bfd_stat_arch_elt): Use vector of containing archive,
+       if file is an archive element.
+       * bfd-in2.h: Regenerate.
+
 2020-02-26  Alan Modra  <amodra@gmail.com>
 
        * archive.c (do_slurp_bsd_armap): Increase minimum parsed_size, and
index 2d56fdad41dc97c366dcc3a01ebff725fb70eb74..44bc7041cdc9ec7eaf85b212b651a44ee9133914 100644 (file)
@@ -7121,7 +7121,8 @@ bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
        BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
 
 #define bfd_stat_arch_elt(abfd, stat) \
-       BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
+       BFD_SEND (abfd->my_archive ? abfd->my_archive : abfd, \
+                 _bfd_stat_arch_elt, (abfd, stat))
 
 #define bfd_update_armap_timestamp(abfd) \
        BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
index 463f94bb945ce1816f6442fe9c50c04c46c53413..1c1238c036a546ccabeceb2f6cebc74d94f83855 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2063,7 +2063,8 @@ DESCRIPTION
 .      BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
 .
 .#define bfd_stat_arch_elt(abfd, stat) \
-.      BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
+.      BFD_SEND (abfd->my_archive ? abfd->my_archive : abfd, \
+.                _bfd_stat_arch_elt, (abfd, stat))
 .
 .#define bfd_update_armap_timestamp(abfd) \
 .      BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))