S12Z: Don't crash when disassembling invalid instructions.

Message ID 20190105110852.12309-1-john@darrington.wattle.id.au
State New
Headers show
Series
  • S12Z: Don't crash when disassembling invalid instructions.
Related show

Commit Message

John Darrington Jan. 5, 2019, 11:08 a.m.
Check for null before dereferencing an operand pointer.  Normally
this situation should never arise, but could happen if a "partial"
instruction is encountered at the end of a file or section.

	* opcodes/s12z-dis.c (print_insn_s12z):  Do not derefernce an
	operand if it is null.
---
 opcodes/s12z-dis.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.11.0

Comments

Nick Clifton Jan. 9, 2019, 4:27 p.m. | #1
Hi John,

> 	* opcodes/s12z-dis.c (print_insn_s12z):  Do not derefernce an

> 	operand if it is null.


Approved, please apply.  But please note that the changelog entry
should go in the opcodes/ChangeLog file, and hence there is no need
for "opcodes/" to appear in the path in the changelog entry.

Cheers
  Nick

Patch

diff --git a/opcodes/s12z-dis.c b/opcodes/s12z-dis.c
index 5db0b43562..d4d5fd7217 100644
--- a/opcodes/s12z-dis.c
+++ b/opcodes/s12z-dis.c
@@ -351,7 +351,7 @@  print_insn_s12z (bfd_vma memaddr, struct disassemble_info* info)
 		 (struct mem_read_abstraction_base *) &mra);
 
   (info->fprintf_func) (info->stream, "%s", mnemonics[(long)operator]);
-  
+
   /* Ship out size sufficies for those instructions which
      need them.  */
   if (osize == -1)
@@ -359,7 +359,7 @@  print_insn_s12z (bfd_vma memaddr, struct disassemble_info* info)
       bool suffix = false;
       for (o = 0; o < n_operands; ++o)
 	{
-	  if (operands[o]->osize != -1)
+	  if (operands[o] && operands[o]->osize != -1)
 	    {
 	      if (!suffix)
 		{