From 16089f320a9226e7cdb73e9fb4266d9e450085b2 Mon Sep 17 00:00:00 2001 From: Thomas Hebb Date: Fri, 29 Apr 2022 21:17:58 -0700 Subject: opcodes: don't assume ELF in riscv, csky, rl78, mep disassemblers Currently, the get_disassembler() implementations for riscv, csky, and rl78--and mep_print_insn() for mep--access ELF variants of union fields without first checking that the bfd actually represents an ELF. This causes undefined behavior and crashes when disassembling non-ELF files (the "binary" BFD, for example). Fix that. --- cpu/mep.opc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'cpu') diff --git a/cpu/mep.opc b/cpu/mep.opc index 6ad0c58..278b445 100644 --- a/cpu/mep.opc +++ b/cpu/mep.opc @@ -1451,12 +1451,15 @@ mep_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info) if (info->section && info->section->owner) { bfd *abfd = info->section->owner; - mep_config_index = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_INDEX_MASK; - /* This instantly redefines MEP_CONFIG, MEP_OMASK, .... MEP_VLIW64 */ + if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) + { + mep_config_index = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_INDEX_MASK; + /* This instantly redefines MEP_CONFIG, MEP_OMASK, .... MEP_VLIW64 */ - cop_type = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_COP_MASK; - if (cop_type == EF_MEP_COP_IVC2) - ivc2 = 1; + cop_type = abfd->tdata.elf_obj_data->elf_header->e_flags & EF_MEP_COP_MASK; + if (cop_type == EF_MEP_COP_IVC2) + ivc2 = 1; + } } /* Picking the right ISA bitmask for the current context is tricky. */ -- cgit v1.1