asan: Null-dereference in _bfd_xcoff_copy_private_bfd_data
authorAlan Modra <amodra@gmail.com>
Sat, 1 Jan 2022 03:22:38 +0000 (13:52 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 1 Jan 2022 03:52:11 +0000 (14:22 +1030)
sec->output_section will be NULL when objcopy removes sections.

* coff-rs6000.c (_bfd_xcoff_copy_private_bfd_data): Protect against
objcopy removing sections.

bfd/coff-rs6000.c

index 1cc2162e7d819c7dddd81944e8e04214f09982a5..20b607403e4a6ba150aa4794324f423a977bc8a4 100644 (file)
@@ -386,7 +386,7 @@ _bfd_xcoff_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
   else
     {
       sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
-      if (sec == NULL)
+      if (sec == NULL || sec->output_section == NULL)
        ox->sntoc = 0;
       else
        ox->sntoc = sec->output_section->target_index;
@@ -396,7 +396,7 @@ _bfd_xcoff_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
   else
     {
       sec = coff_section_from_bfd_index (ibfd, ix->snentry);
-      if (sec == NULL)
+      if (sec == NULL || sec->output_section == NULL)
        ox->snentry = 0;
       else
        ox->snentry = sec->output_section->target_index;