Fix the msp430 disassembler asan regression

This commit is contained in:
pancake 2018-07-18 11:54:52 +02:00
parent bf9d45fa47
commit f98d5c8593
3 changed files with 20 additions and 27 deletions

View File

@ -298,24 +298,18 @@ static int decode_addressing_mode(ut16 instr, ut16 op1, ut16 op2, struct msp430_
static int decode_twoop_opcode(ut16 instr, ut16 op1, ut16 op2, struct msp430_cmd *cmd)
{
int ret;
ut8 opcode;
ut8 opcode = get_twoop_opcode(instr);
opcode = get_twoop_opcode(instr);
snprintf(cmd->instr, MSP430_INSTR_MAXLEN - 1, "%s", two_op_instrs[opcode]);
if (get_bw(instr)) {
strncat(cmd->instr, ".b", MSP430_INSTR_MAXLEN - 1 - strlen(cmd->instr));
snprintf (cmd->instr, MSP430_INSTR_MAXLEN - 1, "%s", two_op_instrs[opcode]);
if (get_bw (instr)) {
strncat (cmd->instr, ".b", MSP430_INSTR_MAXLEN - 1 - strlen(cmd->instr));
}
cmd->opcode = get_twoop_opcode(instr);
ret = decode_addressing_mode(instr, op1, op2, cmd);
return ret;
cmd->opcode = get_twoop_opcode (instr);
return decode_addressing_mode (instr, op1, op2, cmd);
}
static ut8 get_jmp_opcode(ut16 instr)
{
static ut8 get_jmp_opcode(ut16 instr) {
return instr >> 13;
}
@ -448,10 +442,11 @@ static int decode_oneop_opcode(ut16 instr, ut16 op, struct msp430_cmd *cmd)
int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd) {
int ret = -1;
ut16 operand1, operand2;
if (len < 2) {
return -1;
}
ut16 instr = r_read_le16 (in);
ut8 opcode = get_twoop_opcode(instr);
ut8 opcode = get_twoop_opcode (instr);
switch (opcode) {
case MSP430_MOV:
@ -466,13 +461,17 @@ int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd) {
case MSP430_BIS:
case MSP430_XOR:
case MSP430_AND:
if (len >= 6) {
// XXX this conditional is wrong, but seems to be safe
if (len >= 4) {
cmd->type = MSP430_TWOOP;
operand1 = r_read_at_le16 (in, 2);
operand2 = r_read_at_le16 (in, 4);
} else {
operand1 = 0;
operand2 = 0;
}
ret = decode_twoop_opcode(instr, operand1, operand2, cmd);
break;
ret = decode_twoop_opcode (instr, operand1, operand2, cmd);
break;
}
if (ret > 0) {

View File

@ -6,12 +6,9 @@
#include <msp430_disas.h>
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
{
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
struct msp430_cmd cmd;
int ret = msp430_decode_command (buf, len, &cmd);
if (ret > 0) {
if (cmd.operands[0]) {
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s", cmd.instr, cmd.operands);
@ -20,9 +17,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
}
}
op->size = ret;
return ret;
return op->size = ret;
}
RAsmPlugin r_asm_plugin_msp430 = {

View File

@ -9,7 +9,6 @@ static int autoblocksize = 1;
static int disMode = 0;
static void visual_refresh(RCore *core);
static bool snowMode = false;
static RList *snows = NULL;
typedef struct {