aboutsummaryrefslogtreecommitdiff
path: root/opcodes/z8k-dis.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-01-08 11:42:36 +1030
committerAlan Modra <amodra@gmail.com>2020-01-08 21:51:32 +1030
commit030a2e78acf66c5c12e073ec3887a167da7a7195 (patch)
treea96dc0b6fda94acff746f176f72c21aa2beed27d /opcodes/z8k-dis.c
parent4c6ee6465acc58f0f86c44668c4e862901186239 (diff)
downloadgdb-030a2e78acf66c5c12e073ec3887a167da7a7195.zip
gdb-030a2e78acf66c5c12e073ec3887a167da7a7195.tar.gz
gdb-030a2e78acf66c5c12e073ec3887a167da7a7195.tar.bz2
ubsan: z8k: index 10 out of bounds for type 'unsigned int const[10]'
The fix is the additional ARRAY_SIZE test, the rest just tidies variable types rather than adding a cast to avoid warnings. opcodes/ * z8k-dis.c: Include libiberty.h (instr_data_s): Make max_fetched unsigned. (z8k_lookup_instr): Make nibl_index and tabl_index unsigned. Don't exceed byte_info bounds. (output_instr): Make num_bytes unsigned. (unpack_instr): Likewise for nibl_count and loop. * z8kgen.c (gas <opcode_entry_type>): Make noperands, length and idx unsigned. * z8k-opc.h: Regenerate. gas/ * config/tc-z8k.c (md_begin): Make idx unsigned. (get_specific): Likewise for this_index.
Diffstat (limited to 'opcodes/z8k-dis.c')
-rw-r--r--opcodes/z8k-dis.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/opcodes/z8k-dis.c b/opcodes/z8k-dis.c
index 7cd59d8..cb871de 100644
--- a/opcodes/z8k-dis.c
+++ b/opcodes/z8k-dis.c
@@ -20,6 +20,7 @@
#include "sysdep.h"
#include "disassemble.h"
+#include "libiberty.h"
#define DEFINE_TABLE
#include "z8k-opc.h"
@@ -35,7 +36,7 @@ typedef struct
unsigned short words[24];
/* Nibble number of first word not yet fetched. */
- int max_fetched;
+ unsigned int max_fetched;
bfd_vma insn_start;
OPCODES_SIGJMP_BUF bailout;
@@ -189,7 +190,7 @@ print_insn_z8002 (bfd_vma addr, disassemble_info *info)
int
z8k_lookup_instr (unsigned char *nibbles, disassemble_info *info)
{
- int nibl_index, tabl_index;
+ unsigned int nibl_index, tabl_index;
int nibl_matched;
int need_fetch = 0;
unsigned short instr_nibl;
@@ -202,7 +203,9 @@ z8k_lookup_instr (unsigned char *nibbles, disassemble_info *info)
{
nibl_matched = 1;
for (nibl_index = 0;
- nibl_index < z8k_table[tabl_index].length * 2 && nibl_matched;
+ nibl_matched
+ && nibl_index < ARRAY_SIZE (z8k_table[0].byte_info)
+ && nibl_index < z8k_table[tabl_index].length * 2;
nibl_index++)
{
if ((nibl_index % 4) == 0)
@@ -281,7 +284,7 @@ output_instr (instr_data_s *instr_data,
unsigned long addr ATTRIBUTE_UNUSED,
disassemble_info *info)
{
- int num_bytes;
+ unsigned int num_bytes;
char out_str[100];
out_str[0] = 0;
@@ -297,7 +300,7 @@ output_instr (instr_data_s *instr_data,
static void
unpack_instr (instr_data_s *instr_data, int is_segmented, disassemble_info *info)
{
- int nibl_count, loop;
+ unsigned int nibl_count, loop;
unsigned short instr_nibl, instr_byte, instr_word;
long instr_long;
unsigned int tabl_datum, datum_class;