Fix ASAN crash when running afbr ##anal

This commit is contained in:
Riccardo Schirone 2019-01-16 15:03:54 +01:00 committed by radare
parent 8f87d8aa27
commit 2462938a64
3 changed files with 49 additions and 36 deletions

View File

@ -239,7 +239,18 @@ R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i) {
if (i < 0 || i >= bb->ninstr) {
return UT16_MAX;
}
return (i > 0 && (i - 1) < bb->op_pos_size) ? bb->op_pos[i - 1] : 0;
return (i > 0 && (i - 1) < bb->op_pos_size)? bb->op_pos[i - 1]: 0;
}
/* return the address of the i-th instruction in the basicblock bb.
* If the index of the instruction is not valid, it returns UT64_MAX */
R_API ut64 r_anal_bb_opaddr_i(RAnalBlock *bb, int i) {
ut16 offset = r_anal_bb_offset_inst (bb, i);
if (offset == UT16_MAX) {
return UT64_MAX;
}
return bb->addr + offset;
}
/* set the offset of the i-th instruction in the basicblock bb */

View File

@ -1739,10 +1739,11 @@ static int anal_fcn_list_bb(RCore *core, const char *input, bool one) {
switch (mode) {
case 'r':
if (b->jump == UT64_MAX) {
ut64 retaddr = b->addr;
if (b->op_pos) {
retaddr += b->op_pos[b->ninstr - 2];
ut64 retaddr = r_anal_bb_opaddr_i (b, b->ninstr - 1);
if (retaddr == UT64_MAX) {
break;
}
if (!strcmp (input, "*")) {
r_cons_printf ("db 0x%08"PFMT64x"\n", retaddr);
} else if (!strcmp (input, "-*")) {

View File

@ -1325,18 +1325,19 @@ R_API RAnalBlock *r_anal_bb_from_offset(RAnal *anal, ut64 off);
R_API int r_anal_bb_is_in_offset(RAnalBlock *bb, ut64 addr);
R_API bool r_anal_bb_set_offset(RAnalBlock *bb, int i, ut16 v);
R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i);
R_API ut64 r_anal_bb_opaddr_i(RAnalBlock *bb, int i);
R_API ut64 r_anal_bb_opaddr_at(RAnalBlock *bb, ut64 addr);
R_API bool r_anal_bb_op_starts_at(RAnalBlock *bb, ut64 addr);
R_API RAnalBlock *r_anal_bb_get_failbb(RAnalFunction *fcn, RAnalBlock *bb);
R_API RAnalBlock *r_anal_bb_get_jumpbb(RAnalFunction *fcn, RAnalBlock *bb);
/* op.c */
R_API const char *r_anal_stackop_tostring (int s);
R_API const char *r_anal_stackop_tostring(int s);
R_API RAnalOp *r_anal_op_new(void);
R_API void r_anal_op_free(void *op);
R_API bool r_anal_op_fini(RAnalOp *op);
R_API RAnalVar *get_link_var(RAnal *anal, ut64 faddr, RAnalVar *var);
R_API bool r_anal_op_is_eob (RAnalOp *op);
R_API bool r_anal_op_is_eob(RAnalOp *op);
R_API RList *r_anal_op_list_new(void);
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr,
const ut8 *data, int len, int mask);
@ -1344,38 +1345,38 @@ R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr,
const char *hexstr);
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op);
R_API RAnalEsil *r_anal_esil_new (int stacksize, int iotrap, unsigned int addrsize);
R_API void r_anal_esil_trace (RAnalEsil *esil, RAnalOp *op);
R_API void r_anal_esil_trace_list (RAnalEsil *esil);
R_API void r_anal_esil_trace_show (RAnalEsil *esil, int idx);
R_API bool r_anal_esil_set_pc (RAnalEsil *esil, ut64 addr);
R_API int r_anal_esil_setup (RAnalEsil *esil, RAnal *anal, int romem, int stats, int nonull);
R_API void r_anal_esil_free (RAnalEsil *esil);
R_API int r_anal_esil_runword (RAnalEsil *esil, const char *word);
R_API int r_anal_esil_parse (RAnalEsil *esil, const char *str);
R_API int r_anal_esil_dumpstack (RAnalEsil *esil);
R_API int r_anal_esil_mem_read (RAnalEsil *esil, ut64 addr, ut8 *buf, int len);
R_API int r_anal_esil_mem_write (RAnalEsil *esil, ut64 addr, const ut8 *buf, int len);
R_API int r_anal_esil_reg_read (RAnalEsil *esil, const char *regname, ut64 *num, int *size);
R_API int r_anal_esil_reg_write (RAnalEsil *esil, const char *dst, ut64 num);
R_API int r_anal_esil_pushnum (RAnalEsil *esil, ut64 num);
R_API bool r_anal_esil_push (RAnalEsil *esil, const char *str);
R_API char *r_anal_esil_pop (RAnalEsil *esil);
R_API int r_anal_esil_set_op (RAnalEsil *esil, const char *op, RAnalEsilOp code);
R_API void r_anal_esil_stack_free (RAnalEsil *esil);
R_API int r_anal_esil_get_parm_type (RAnalEsil *esil, const char *str);
R_API int r_anal_esil_get_parm (RAnalEsil *esil, const char *str, ut64 *num);
R_API int r_anal_esil_condition (RAnalEsil *esil, const char *str);
R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap, unsigned int addrsize);
R_API void r_anal_esil_trace(RAnalEsil *esil, RAnalOp *op);
R_API void r_anal_esil_trace_list(RAnalEsil *esil);
R_API void r_anal_esil_trace_show(RAnalEsil *esil, int idx);
R_API bool r_anal_esil_set_pc(RAnalEsil *esil, ut64 addr);
R_API int r_anal_esil_setup(RAnalEsil *esil, RAnal *anal, int romem, int stats, int nonull);
R_API void r_anal_esil_free(RAnalEsil *esil);
R_API int r_anal_esil_runword(RAnalEsil *esil, const char *word);
R_API int r_anal_esil_parse(RAnalEsil *esil, const char *str);
R_API int r_anal_esil_dumpstack(RAnalEsil *esil);
R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len);
R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len);
R_API int r_anal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size);
R_API int r_anal_esil_reg_write(RAnalEsil *esil, const char *dst, ut64 num);
R_API int r_anal_esil_pushnum(RAnalEsil *esil, ut64 num);
R_API bool r_anal_esil_push(RAnalEsil *esil, const char *str);
R_API char *r_anal_esil_pop(RAnalEsil *esil);
R_API int r_anal_esil_set_op(RAnalEsil *esil, const char *op, RAnalEsilOp code);
R_API void r_anal_esil_stack_free(RAnalEsil *esil);
R_API int r_anal_esil_get_parm_type(RAnalEsil *esil, const char *str);
R_API int r_anal_esil_get_parm(RAnalEsil *esil, const char *str, ut64 *num);
R_API int r_anal_esil_condition(RAnalEsil *esil, const char *str);
// esil_interrupt.c
R_API void r_anal_esil_interrupts_init (RAnalEsil *esil);
R_API RAnalEsilInterrupt *r_anal_esil_interrupt_new (RAnalEsil *esil, ut32 src_id, RAnalEsilInterruptHandler *ih);
R_API void r_anal_esil_interrupt_free (RAnalEsil *esil, RAnalEsilInterrupt *intr);
R_API bool r_anal_esil_set_interrupt (RAnalEsil *esil, RAnalEsilInterrupt *intr);
R_API int r_anal_esil_fire_interrupt (RAnalEsil *esil, ut32 intr_num);
R_API bool r_anal_esil_load_interrupts (RAnalEsil *esil, RAnalEsilInterruptHandler **handlers, ut32 src_id);
R_API bool r_anal_esil_load_interrupts_from_lib (RAnalEsil *esil, const char *path);
R_API void r_anal_esil_interrupts_fini (RAnalEsil *esil);
R_API void r_anal_esil_interrupts_init(RAnalEsil *esil);
R_API RAnalEsilInterrupt *r_anal_esil_interrupt_new(RAnalEsil *esil, ut32 src_id, RAnalEsilInterruptHandler *ih);
R_API void r_anal_esil_interrupt_free(RAnalEsil *esil, RAnalEsilInterrupt *intr);
R_API bool r_anal_esil_set_interrupt(RAnalEsil *esil, RAnalEsilInterrupt *intr);
R_API int r_anal_esil_fire_interrupt(RAnalEsil *esil, ut32 intr_num);
R_API bool r_anal_esil_load_interrupts(RAnalEsil *esil, RAnalEsilInterruptHandler **handlers, ut32 src_id);
R_API bool r_anal_esil_load_interrupts_from_lib(RAnalEsil *esil, const char *path);
R_API void r_anal_esil_interrupts_fini(RAnalEsil *esil);
R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly);
R_API void r_anal_esil_stats(RAnalEsil *esil, int enable);