]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Fix buffer overflow on print_insn_riscv
authorTsukasa OI <research_trasio@irq.a4lg.com>
Tue, 4 Oct 2022 08:35:30 +0000 (08:35 +0000)
committerTsukasa OI <research_trasio@irq.a4lg.com>
Tue, 4 Oct 2022 13:21:41 +0000 (13:21 +0000)
Because riscv_insn_length started to support instructions up to 176-bit,
we need to increase packet buffer size to 176-bit in size.

include/ChangeLog:

* opcode/riscv.h (RISCV_MAX_INSN_LEN): Max instruction length for
use in buffer size.

opcodes/ChangeLog:

* riscv-dis.c (print_insn_riscv): Increase buffer size for max
176-bit length instructions.

include/opcode/riscv.h
opcodes/riscv-dis.c

index 9cc001629db017b5437e457ffd59886592feb895..f173a2eca2596e54b877a185d6e0f20c5dbd84f8 100644 (file)
@@ -40,6 +40,8 @@ static inline unsigned int riscv_insn_length (insn_t insn)
   /* 80- ... 176-bit instructions.  */
   if ((insn & 0x7f) == 0x7f && (insn & 0x7000) != 0x7000)
     return 10 + ((insn >> 11) & 0xe);
+  /* Maximum value returned by this function.  */
+#define RISCV_MAX_INSN_LEN 22
   /* Longer instructions not supported at the moment.  */
   return 2;
 }
index 031c19334fa39f8a22fd9221d2b17470d03fec96..2c0aed13e754fb45742f3215229435fc177dcc07 100644 (file)
@@ -1000,7 +1000,7 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
 int
 print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info)
 {
-  bfd_byte packet[8];
+  bfd_byte packet[RISCV_MAX_INSN_LEN];
   insn_t insn = 0;
   bfd_vma dump_size;
   int status;