From 56119f04b269045d9134f28f734bfaf97763cf46 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 10 Feb 2017 12:03:28 +0100 Subject: [PATCH] Fix infinite loop in pif and fix pif test --- libr/core/cmd_print.c | 8 +++++--- libr/core/disasm.c | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index ab19c4d065..e5306d3f80 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -2995,11 +2995,13 @@ static int cmd_print(void *data, const char *input) { case 'f': // "pif" if (l != 0) { RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, - R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM); + R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (f) { ut32 bsz = core->blocksize; - r_core_block_size (core, r_anal_fcn_realsize (f)); - r_core_print_disasm_instructions (core, 0, 0); + // int fsz = r_anal_fcn_realsize (f); + int fsz = r_anal_fcn_size (f); // we want max-min here + r_core_block_size (core, fsz); + r_core_print_disasm_instructions (core, fsz, 0); r_core_block_size (core, bsz); } else { r_core_print_disasm_instructions (core, diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 8794d9faa4..ca7fe704c3 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -3793,6 +3793,10 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc ds->analop.size = ret; ds->asmop.size = ret; } + /* fix infinite loop */ + if (ret < 1) { + ret = 1; + } len += R_MAX (0, ret); if (ds->hint && ds->hint->opcode) { free (ds->opstr); @@ -3826,8 +3830,8 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc } } core->parser->hint = ds->hint; - r_parse_filter (core->parser, core->flags, - ds->asmop.buf_asm, ds->str, sizeof (ds->str), core->print->big_endian); + r_parse_filter (core->parser, core->flags, ds->asmop.buf_asm, ds->str, + sizeof (ds->str), core->print->big_endian); ds->opstr = strdup (ds->str); asm_str = colorize_asm_string (core, ds); core->parser->flagspace = ofs;