From 4a90ce955e5bcde074b8616ff9d20f9939a9a358 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 29 Apr 2019 16:05:54 +0200 Subject: [PATCH] S12Z: Opcodes: Fix crash when trying to decode a truncated operation. opcodes/ * s12z-opc.c (shift_discrim): Return OP_INVALID when reading fails. gas/ * testsuite/gas/s12z/truncated.d: New file. * testsuite/gas/s12z/truncated.s: New file. * testsuite/gas/s12z/s12z.exp: Add new test. --- gas/ChangeLog | 6 ++++++ gas/testsuite/gas/s12z/s12z.exp | 1 + gas/testsuite/gas/s12z/truncated.d | 17 +++++++++++++++++ gas/testsuite/gas/s12z/truncated.s | 3 +++ opcodes/ChangeLog | 4 ++++ opcodes/s12z-opc.c | 2 +- 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gas/testsuite/gas/s12z/truncated.d create mode 100644 gas/testsuite/gas/s12z/truncated.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 81fcdcc466..9f5e9baca9 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,9 @@ +2019-04-29 John Darrington + + * testsuite/gas/s12z/truncated.d: New file. + * testsuite/gas/s12z/truncated.s: New file. + * testsuite/gas/s12z/s12z.exp: Add new test. + 2019-04-26 Andrew Bennett Faraz Shahbazker diff --git a/gas/testsuite/gas/s12z/s12z.exp b/gas/testsuite/gas/s12z/s12z.exp index 612fda765b..e8a0744222 100644 --- a/gas/testsuite/gas/s12z/s12z.exp +++ b/gas/testsuite/gas/s12z/s12z.exp @@ -117,6 +117,7 @@ run_dump_test lea-immu18 run_dump_test ext24-ld-xy run_dump_test st-xy run_dump_test bit-manip-invalid +run_dump_test truncated # Symbol related tests run_dump_test opr-symbol diff --git a/gas/testsuite/gas/s12z/truncated.d b/gas/testsuite/gas/s12z/truncated.d new file mode 100644 index 0000000000..c6af5482eb --- /dev/null +++ b/gas/testsuite/gas/s12z/truncated.d @@ -0,0 +1,17 @@ +#objdump: -d +#name: Handle truncated instruction gracefully. +#source: truncated.s + + +.*: file format elf32-s12z + + +Disassembly of section .text: + +00000000 <.text>: + 0: 01 nop + 1: Address 0x0000000000000002 is out of bounds. +Address 0x0000000000000002 is out of bounds. +Address 0x0000000000000002 is out of bounds. +!!invalid!! + diff --git a/gas/testsuite/gas/s12z/truncated.s b/gas/testsuite/gas/s12z/truncated.s new file mode 100644 index 0000000000..a52c3908f6 --- /dev/null +++ b/gas/testsuite/gas/s12z/truncated.s @@ -0,0 +1,3 @@ + nop + ;; This is a valid start of an instruction. But it stops in the middle. + dc.b 0x14 diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 0c2980f5ac..1c9bdbc6ef 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,7 @@ +2019-04-29 John Darrington + + * s12z-opc.c (shift_discrim): Return OP_INVALID when reading fails. + 2019-04-26 Andrew Bennett Faraz Shahbazker diff --git a/opcodes/s12z-opc.c b/opcodes/s12z-opc.c index e40f90e43f..eef097dfd4 100644 --- a/opcodes/s12z-opc.c +++ b/opcodes/s12z-opc.c @@ -2292,7 +2292,7 @@ shift_discrim (struct mem_read_abstraction_base *mra, enum optr hint ATTRIBUTE_ uint8_t sb; int status = mra->read (mra, 0, 1, &sb); if (status < 0) - return status; + return OP_INVALID; enum SB_DIR dir = (sb & 0x40) ? SB_LEFT : SB_RIGHT; enum SB_TYPE type = (sb & 0x80) ? SB_ARITHMETIC : SB_LOGICAL; -- 2.34.1