Fix crash in m68k capstone disassembler

This commit is contained in:
pancake 2017-10-09 15:58:08 +02:00
parent a7230ca359
commit 42ce366601
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
diff --git a/arch/M68K/M68KInstPrinter.c b/arch/M68K/M68KInstPrinter.c
index c545115..aec6a05 100644
--- a/arch/M68K/M68KInstPrinter.c
+++ b/arch/M68K/M68KInstPrinter.c
@@ -28,7 +28,8 @@
#ifndef CAPSTONE_DIET
static const char* s_spacing = " ";
-static const char* s_reg_names[] = {
+#define S_REG_NAMES_COUNT 47
+static const char* s_reg_names[S_REG_NAMES_COUNT] = {
"invalid",
"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
@@ -326,6 +327,9 @@ const char* M68K_reg_name(csh handle, unsigned int reg)
#ifdef CAPSTONE_DIET
return NULL;
#else
+ if (reg >= S_REG_NAMES_COUNT) {
+ return NULL;
+ }
return s_reg_names[(int)reg];
#endif
}