asan: uninitialised write in bfd_mach_o_write_contents
authorAlan Modra <amodra@gmail.com>
Sat, 4 Jun 2022 09:01:54 +0000 (18:31 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 4 Jun 2022 11:27:36 +0000 (20:57 +0930)
* mach-o.c (bfd_mach_o_write_contents): Always set
bfd_mach_o_dyld_info_command *_off fields.

bfd/mach-o.c

index 9f3f1f13e4eced82f6133c693c43b766199e0947..c761544e21e1a3521aa38141a070cf4962c3e570 100644 (file)
@@ -2656,31 +2656,16 @@ bfd_mach_o_write_contents (bfd *abfd)
        {
          bfd_mach_o_dyld_info_command *di = &cmd->command.dyld_info;
 
-         if (di->rebase_size != 0)
-           {
-             di->rebase_off = mdata->filelen;
-             mdata->filelen += di->rebase_size;
-           }
-         if (di->bind_size != 0)
-           {
-             di->bind_off = mdata->filelen;
-             mdata->filelen += di->bind_size;
-           }
-         if (di->weak_bind_size != 0)
-           {
-             di->weak_bind_off = mdata->filelen;
-             mdata->filelen += di->weak_bind_size;
-           }
-         if (di->lazy_bind_size != 0)
-           {
-             di->lazy_bind_off = mdata->filelen;
-             mdata->filelen += di->lazy_bind_size;
-           }
-         if (di->export_size != 0)
-           {
-             di->export_off = mdata->filelen;
-             mdata->filelen += di->export_size;
-           }
+         di->rebase_off = di->rebase_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->rebase_size;
+         di->bind_off = di->bind_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->bind_size;
+         di->weak_bind_off = di->weak_bind_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->weak_bind_size;
+         di->lazy_bind_off = di->lazy_bind_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->lazy_bind_size;
+         di->export_off = di->export_size != 0 ? mdata->filelen : 0;
+         mdata->filelen += di->export_size;
        }
        break;
       case BFD_MACH_O_LC_LOAD_DYLIB: