[binutils-gdb] ubsan: tic4x: segv and signed shifts

Alan Modra amodra@sourceware.org
Wed Dec 11 01:14:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=66152f16685fe63a5b2eb941c2d7057bbff5cfe5

commit 66152f16685fe63a5b2eb941c2d7057bbff5cfe5
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Dec 11 08:47:35 2019 +1030

    ubsan: tic4x: segv and signed shifts
    
    	* tic4x-dis.c (tic4x_print_register): Formatting.  Don't segfault
    	on NULL registertable entry.
    	(tic4x_hash_opcode): Use unsigned arithmetic.

Diff:
---
 opcodes/ChangeLog   |  6 ++++++
 opcodes/tic4x-dis.c | 16 +++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index a8e1d30..3ae93c1 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,11 @@
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
+	* tic4x-dis.c (tic4x_print_register): Formatting.  Don't segfault
+	on NULL registertable entry.
+	(tic4x_hash_opcode): Use unsigned arithmetic.
+
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
 	* s12z-opc.c (z_decode_signed_value): Avoid signed overflow.
 
 2019-12-11  Alan Modra  <amodra@gmail.com>
diff --git a/opcodes/tic4x-dis.c b/opcodes/tic4x-dis.c
index de3d536..d9f95c9 100644
--- a/opcodes/tic4x-dis.c
+++ b/opcodes/tic4x-dis.c
@@ -137,17 +137,19 @@ tic4x_print_register (struct disassemble_info *info, unsigned long regno)
     {
       registertable = xmalloc (sizeof (tic4x_register_t *) * REG_TABLE_SIZE);
       for (i = 0; i < tic3x_num_registers; i++)
-	registertable[tic3x_registers[i].regno] = (tic4x_register_t *) (tic3x_registers + i);
+	registertable[tic3x_registers[i].regno]
+	  = (tic4x_register_t *) (tic3x_registers + i);
       if (IS_CPU_TIC4X (tic4x_version))
 	{
 	  /* Add C4x additional registers, overwriting
 	     any C3x registers if necessary.  */
 	  for (i = 0; i < tic4x_num_registers; i++)
-	    registertable[tic4x_registers[i].regno] =
-	      (tic4x_register_t *)(tic4x_registers + i);
+	    registertable[tic4x_registers[i].regno]
+	      = (tic4x_register_t *)(tic4x_registers + i);
 	}
     }
-  if ((int) regno > (IS_CPU_TIC4X (tic4x_version) ? TIC4X_REG_MAX : TIC3X_REG_MAX))
+  if (regno > (IS_CPU_TIC4X (tic4x_version) ? TIC4X_REG_MAX : TIC3X_REG_MAX)
+      || registertable[regno] == NULL)
     return 0;
   if (info != NULL)
     (*info->fprintf_func) (info->stream, "%s", registertable[regno]->name);
@@ -639,9 +641,9 @@ tic4x_hash_opcode (tic4x_inst_t **optable,
 		   const tic4x_inst_t *inst,
 		   const unsigned long tic4x_oplevel)
 {
-  int j;
-  int opcode = inst->opcode >> (32 - TIC4X_HASH_SIZE);
-  int opmask = inst->opmask >> (32 - TIC4X_HASH_SIZE);
+  unsigned int j;
+  unsigned int opcode = inst->opcode >> (32 - TIC4X_HASH_SIZE);
+  unsigned int opmask = inst->opmask >> (32 - TIC4X_HASH_SIZE);
 
   /* Use a TIC4X_HASH_SIZE bit index as a hash index.  We should
      have unique entries so there's no point having a linked list



More information about the Binutils-cvs mailing list