From: H.J. Lu Date: Tue, 16 Aug 2022 15:25:49 +0000 (-0700) Subject: i386: Add MAX_OPERAND_BUFFER_SIZE X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9096fc28c62741bfb7962eb5dfdee28a7b1d1345;p=binutils-gdb.git i386: Add MAX_OPERAND_BUFFER_SIZE When displaying operands, invalid opcodes may overflow operand buffer due to additional styling characters. Each style is encoded with 3 bytes. Define MAX_OPERAND_BUFFER_SIZE for operand buffer size and increase it from 100 bytes to 128 bytes to accommodate 9 sets of styles in an operand. gas/ PR binutils/29483 * testsuite/gas/i386/i386.exp: Run pr29483. * testsuite/gas/i386/pr29483.d: New file. * testsuite/gas/i386/pr29483.s: Likewise. opcodes/ PR binutils/29483 * i386-dis.c (MAX_OPERAND_BUFFER_SIZE): New. (obuf): Replace 100 with MAX_OPERAND_BUFFER_SIZE. (staging_area): Likewise. (op_out): Likewise. --- diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp index 1d27dfc78b8..68576be8d78 100644 --- a/gas/testsuite/gas/i386/i386.exp +++ b/gas/testsuite/gas/i386/i386.exp @@ -1346,6 +1346,7 @@ if [gas_64_check] then { run_dump_test ehinterp } run_dump_test pr27198 + run_dump_test pr29483 set ASFLAGS "$old_ASFLAGS --64" diff --git a/gas/testsuite/gas/i386/pr29483.d b/gas/testsuite/gas/i386/pr29483.d new file mode 100644 index 00000000000..6592ecd4dca --- /dev/null +++ b/gas/testsuite/gas/i386/pr29483.d @@ -0,0 +1,10 @@ +#objdump: -dw + +.*: +file format .* + + +Disassembly of section .text: + +0+ : + +[a-f0-9]+: 65 62 62 7d 97 a0 94 ff 20 20 20 ae vpscatterdd %xmm26,%gs:-0x51dfdfe0\(%rdi,%xmm23,8\)\{bad\}\{%k7\}\{z\}/\(bad\) +#pass diff --git a/gas/testsuite/gas/i386/pr29483.s b/gas/testsuite/gas/i386/pr29483.s new file mode 100644 index 00000000000..6b133acf17b --- /dev/null +++ b/gas/testsuite/gas/i386/pr29483.s @@ -0,0 +1,3 @@ + .text +pr29483: + .byte 0x65,0x62,0x62,0x7d,0x97,0xa0,0x94,0xff,0x20,0x20,0x20,0xae diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 1761df583da..c1166a4446c 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -119,6 +119,9 @@ static void DistinctDest_Fixup (instr_info *, int, int); buffers. See oappend_insert_style for more details. */ #define STYLE_MARKER_CHAR '\002' +/* The maximum operand buffer size. */ +#define MAX_OPERAND_BUFFER_SIZE 128 + struct dis_private { /* Points to first byte not fetched. */ bfd_byte *max_fetched; @@ -165,7 +168,7 @@ struct instr_info current instruction. */ int evex_used; - char obuf[100]; + char obuf[MAX_OPERAND_BUFFER_SIZE]; char *obufp; char *mnemonicendp; unsigned char *start_codep; @@ -9275,7 +9278,7 @@ i386_dis_printf (instr_info *ins, enum disassembler_style style, va_list ap; enum disassembler_style curr_style = style; char *start, *curr; - char staging_area[100]; + char staging_area[MAX_OPERAND_BUFFER_SIZE]; int res; va_start (ap, fmt); @@ -9377,7 +9380,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int intel_syntax) .last_seg_prefix = -1, .fwait_prefix = -1, }; - char op_out[MAX_OPERANDS][100]; + char op_out[MAX_OPERANDS][MAX_OPERAND_BUFFER_SIZE]; priv.orig_sizeflag = AFLAG | DFLAG; if ((info->mach & bfd_mach_i386_i386) != 0)