diff --git a/libr/anal/p/anal_msp430.c b/libr/anal/p/anal_msp430.c index eb72290555..02c063178f 100644 --- a/libr/anal/p/anal_msp430.c +++ b/libr/anal/p/anal_msp430.c @@ -14,7 +14,7 @@ static int msp430_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int le memset (&cmd, 0, sizeof (cmd)); memset (op, 0, sizeof (RAnalOp)); - ret = op->size = msp430_decode_command (buf, &cmd); + ret = op->size = msp430_decode_command (buf, len, &cmd); if (ret < 0) { return ret; diff --git a/libr/asm/arch/msp430/msp430_disas.c b/libr/asm/arch/msp430/msp430_disas.c index 170c4ac656..969db61333 100644 --- a/libr/asm/arch/msp430/msp430_disas.c +++ b/libr/asm/arch/msp430/msp430_disas.c @@ -445,16 +445,13 @@ static int decode_oneop_opcode(ut16 instr, ut16 op, struct msp430_cmd *cmd) return ret; } -int msp430_decode_command(const ut8 *in, struct msp430_cmd *cmd) -{ +int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd) { int ret = -1; - ut16 instr; ut16 operand1, operand2; - ut8 opcode; - instr = r_read_le16 (in); + ut16 instr = r_read_le16 (in); - opcode = get_twoop_opcode(instr); + ut8 opcode = get_twoop_opcode(instr); switch (opcode) { case MSP430_MOV: @@ -469,9 +466,11 @@ int msp430_decode_command(const ut8 *in, struct msp430_cmd *cmd) case MSP430_BIS: case MSP430_XOR: case MSP430_AND: - cmd->type = MSP430_TWOOP; - operand1 = r_read_at_le16 (in, 2); - operand2 = r_read_at_le16 (in, 4); + if (len >= 6) { + cmd->type = MSP430_TWOOP; + operand1 = r_read_at_le16 (in, 2); + operand2 = r_read_at_le16 (in, 4); + } ret = decode_twoop_opcode(instr, operand1, operand2, cmd); break; } @@ -480,10 +479,11 @@ int msp430_decode_command(const ut8 *in, struct msp430_cmd *cmd) return ret; } - ret = decode_jmp(instr, cmd); + ret = decode_jmp (instr, cmd); - if (ret > 0) + if (ret > 0) { return ret; + } operand1 = r_read_at_le16 (in, 2); ret = decode_oneop_opcode(instr, operand1, cmd); diff --git a/libr/asm/arch/msp430/msp430_disas.h b/libr/asm/arch/msp430/msp430_disas.h index 100038617c..5437a86467 100644 --- a/libr/asm/arch/msp430/msp430_disas.h +++ b/libr/asm/arch/msp430/msp430_disas.h @@ -84,5 +84,5 @@ struct msp430_cmd { char operands[MSP430_INSTR_MAXLEN]; }; -int msp430_decode_command(const ut8 *instr, struct msp430_cmd *cmd); +int msp430_decode_command(const ut8 *instr, int len, struct msp430_cmd *cmd); #endif /* MSP430_DISAS_H */ diff --git a/libr/asm/p/asm_msp430.c b/libr/asm/p/asm_msp430.c index c6339aa645..f5950bcaee 100644 --- a/libr/asm/p/asm_msp430.c +++ b/libr/asm/p/asm_msp430.c @@ -8,10 +8,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - int ret; struct msp430_cmd cmd; - ret = msp430_decode_command (buf, &cmd); + int ret = msp430_decode_command (buf, len, &cmd); if (ret > 0) { if (cmd.operands[0]) {