S12Z: Opcodes: Fix crash when trying to decode a truncated operation.
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 29 Apr 2019 14:05:54 +0000 (16:05 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 29 Apr 2019 14:10:21 +0000 (16:10 +0200)
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
gas/testsuite/gas/s12z/s12z.exp
gas/testsuite/gas/s12z/truncated.d [new file with mode: 0644]
gas/testsuite/gas/s12z/truncated.s [new file with mode: 0644]
opcodes/ChangeLog
opcodes/s12z-opc.c

index 81fcdcc46655efbfd410d9d4544cea946358adf8..9f5e9baca9267587713e5723b1d02ed1f880548a 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-29  John Darrington <john@darrington.wattle.id.au>
+
+        * 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  <andrew.bennett@imgtec.com>
            Faraz Shahbazker  <fshahbazker@wavecomp.com>
 
index 612fda765be5468e2347516a93b98718e47f94a9..e8a074422278c5007b40db30654cc505822be87f 100644 (file)
@@ -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 (file)
index 0000000..c6af548
--- /dev/null
@@ -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 (file)
index 0000000..a52c390
--- /dev/null
@@ -0,0 +1,3 @@
+       nop
+       ;; This is a valid start of an instruction.  But it stops in the middle.
+       dc.b 0x14
index 0c2980f5ac73d391c70d126c092a382b60d56f23..1c9bdbc6ef73ddca95183178a71dabe6b4a288dd 100644 (file)
@@ -1,3 +1,7 @@
+2019-04-29  John Darrington  <john@darrington.wattle.id.au>
+
+        * s12z-opc.c (shift_discrim): Return OP_INVALID when reading fails.
+
 2019-04-26  Andrew Bennett  <andrew.bennett@imgtec.com>
            Faraz Shahbazker  <fshahbazker@wavecomp.com>
 
index e40f90e43ff6da0a6ced6b3e215d71906159978b..eef097dfd48667d1add51d9a0137a294d3d2bfe4 100644 (file)
@@ -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;
This page took 0.031535 seconds and 4 git commands to generate.