Bug 27814 - objdump crashes when disassembling a non-ELF RISC-V binary
Summary: objdump crashes when disassembling a non-ELF RISC-V binary
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.36
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-03 15:17 UTC by Job Noorman
Modified: 2022-06-22 06:31 UTC (History)
3 users (show)

See Also:
Host:
Target: RISC-V
Build:
Last reconfirmed:


Attachments
Fix for missing null-check (485 bytes, patch)
2021-05-03 15:17 UTC, Job Noorman
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Job Noorman 2021-05-03 15:17:19 UTC
Created attachment 13418 [details]
Fix for missing null-check

objdump crashes when disassembling a non-ELF RISC-V binary due to a missing null-pointer check. I've attached a patch.
Comment 1 Jim Wilson 2021-05-03 19:10:01 UTC
Patches for the GNU toolchain require an FSF copyright assignment, except for some trivial patches.  Do you have a copyright assignment?  mtvec is a RISC-V CSR so it seems unlikely to be your name.  I would need a name to check the records at the FSF.  Are you interested in getting an assignment?  If you don't or can't get an assignment, then it would be useful to give a description of the problem so someone else with an assignment can write the patch.
Comment 2 Job Noorman 2021-05-03 19:17:57 UTC
I don't have a copyright assignment yet but I would be interested in getting one. What is the procedure for this?

This patch is quite trivial by the way so we might be able to skip it in this case?
Comment 3 Sourceware Commits 2021-05-18 01:27:56 UTC
The master branch has been updated by Nelson Chu <nelsonc1225@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=113bb7618a4b52c5fc8fdc0e82b2cd9f72471f72

commit 113bb7618a4b52c5fc8fdc0e82b2cd9f72471f72
Author: Job Noorman <mtvec@pm.me>
Date:   Tue May 18 08:41:11 2021 +0800

    RISC-V: PR27814, Objdump crashes when disassembling a non-ELF RISC-V binary.
    
    2021-05-18  Job Noorman  <mtvec@pm.me>
    
    opcodes/
        PR 27814
        * riscv-dis.c (riscv_get_disassembler): Get elf attributes only for
        the elf objects.
Comment 4 Nelson Chu 2021-05-18 01:30:56 UTC
Hi Job Noorman,

Thanks for reporting this.  I have committed this fix, with the name and email from your account.

So marked as resolved and fixed.
Comment 5 Tom Hebb 2022-04-30 16:36:41 UTC
FYI, the original fix for this bug was not correct in all cases since it would try to access any non-NULL backend_data for any BFD as if it were for an ELF. My patch at https://sourceware.org/pipermail/binutils/2022-April/120619.html, which just got committed, fixes the issue properly (as far as I can tell) and also fixes a similar issue in several other architectures.