diff --git a/libr/asm/arch/hexagon/gnu/hexagon-dis.c b/libr/asm/arch/hexagon/gnu/hexagon-dis.c index 5799004fd0..fda3fb1d2e 100644 --- a/libr/asm/arch/hexagon/gnu/hexagon-dis.c +++ b/libr/asm/arch/hexagon/gnu/hexagon-dis.c @@ -48,7 +48,7 @@ hexagon_dis_inst( if (!hexagon_dis_opcode(instrBuffer, insn, address, opcode, &errmsg)) { /* Some kind of error! */ if (errmsg) { - (*info->fprintf_func) (info->stream, errmsg); + (*info->fprintf_func) (info->stream, "%s", errmsg); strcpy(instrBuffer, ""); } } diff --git a/libr/bin/format/objc/mach0_classes.c b/libr/bin/format/objc/mach0_classes.c index 5d60222eb2..0de0a4418f 100644 --- a/libr/bin/format/objc/mach0_classes.c +++ b/libr/bin/format/objc/mach0_classes.c @@ -295,14 +295,17 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *arch, RBinClass *klass) { if (r != 0) { struct MACH0_(obj_t) *bin = (struct MACH0_(obj_t) *) arch->o->bin_obj; int is_crypted = bin->has_crypto; - if (r + left < r) return; - if (r > arch->size || r + left > arch->size) return; - + if (r + left < r) { + goto error; + } + if (r > arch->size || r + left > arch->size) { + goto error; + } if (is_crypted == 1) { type = strdup ("some_encrypted_data"); - left = strlen (name) + 1; + // left = strlen (name) + 1; } else { - type = malloc (left); + type = calloc (1, left); r_buf_read_at (arch->buf, r, (ut8 *)type, left); } field->type = strdup (type); @@ -316,8 +319,7 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *arch, RBinClass *klass) { return; error: - R_FREE (field); - return; + r_bin_field_free (field); } /////////////////////////////////////////////////////////////////////////////// diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index fe0e72c7b1..fadf884ef7 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -1420,9 +1420,10 @@ static int cmd_debug_map(RCore *core, const char *input) { if (input[1]=='*') { mode = "-r "; } - ptr = strdup (r_str_trim_head ((char*)input + 2)); + ptr = strdup (r_str_chop_ro (input + 2)); if (!ptr || !*ptr) { r_core_cmd (core, "dmm", 0); + free (ptr); break; } i = r_str_word_set0 (ptr); @@ -2435,27 +2436,29 @@ static void backtrace_vars(RCore *core, RList *frames) { ut64 b = f->bp ? f->bp : dbp; r_reg_setv (r, bp, s); r_reg_setv (r, sp, b); - char flagdesc[1024], flagdesc2[1024]; - RFlagItem *fi = r_flag_get_at (core->flags, f->addr, true); - flagdesc[0] = flagdesc2[0] = 0; - if (f) { - if (fi->offset != f->addr) { - int delta = (int)(f->addr - fi->offset); - if (delta > 0) { - snprintf (flagdesc, sizeof (flagdesc), - "%s+%d", fi->name, delta); - } else if (delta < 0) { - snprintf (flagdesc, sizeof (flagdesc), - "%s%d", fi->name, delta); - } else { - snprintf (flagdesc, sizeof (flagdesc), - "%s", fi->name); - } - } else { - snprintf (flagdesc, sizeof (flagdesc), - "%s", fi->name); - } +////////// + char flagdesc[1024], flagdesc2[1024]; + RFlagItem *fi = r_flag_get_at (core->flags, f->addr, true); + flagdesc[0] = flagdesc2[0] = 0; + if (fi) { + if (fi->offset != f->addr) { + int delta = (int)(f->addr - fi->offset); + if (delta > 0) { + snprintf (flagdesc, sizeof (flagdesc), + "%s+%d", fi->name, delta); + } else if (delta < 0) { + snprintf (flagdesc, sizeof (flagdesc), + "%s%d", fi->name, delta); + } else { + snprintf (flagdesc, sizeof (flagdesc), + "%s", fi->name); } + } else { + snprintf (flagdesc, sizeof (flagdesc), + "%s", fi->name); + } + } +////////// RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, f->addr, 0); // char *str = r_str_newf ("[frame %d]", n); r_cons_printf ("%d 0x%08"PFMT64x" sp: 0x%08"PFMT64x" %-5d" @@ -2921,6 +2924,7 @@ static void r_core_cmd_bp(RCore *core, const char *input) { case 'w': // "dbw" input++; // skip 'w' watch = true; + // passthru case ' ': // "db" for (p = input + 2; *p == ' '; p++); if (*p == '-') { @@ -3202,17 +3206,16 @@ static void debug_trace_calls(RCore *core, const char *input) { return; } if (*input == ' ') { - ut64 first_n; - input = r_str_trim_head (input); - first_n = r_num_math (core->num, input); + input = r_str_chop_ro (input); + ut64 first_n = r_num_math (core->num, input); input = strchr (input, ' '); if (input) { - input = r_str_trim_head (input); + input = r_str_chop_ro (input); from = first_n; to = r_num_math (core->num, input); input = strchr (input, ' '); if (input) { - input = r_str_trim_head (input); + input = r_str_chop_ro (input); final_addr = r_num_math (core->num, input); } } else { diff --git a/libr/core/cmd_info.c b/libr/core/cmd_info.c index 1b6461516c..3deeee4add 100644 --- a/libr/core/cmd_info.c +++ b/libr/core/cmd_info.c @@ -759,7 +759,7 @@ static int cmd_info(void *data, const char *input) { break; } input++; - if ((*input == 'j' || *input == 'q') && !input[1]) { + if ((*input == 'j' || *input == 'q') && (input[0] && !input[1])) { break; } } diff --git a/libr/core/linux_heap_jemalloc.c b/libr/core/linux_heap_jemalloc.c index ac0fad3d98..df91fd9dbb 100644 --- a/libr/core/linux_heap_jemalloc.c +++ b/libr/core/linux_heap_jemalloc.c @@ -234,9 +234,11 @@ static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { } if (narenas == 0) { eprintf ("No arenas allocated.\n"); + free (stats); return; } if (narenas == GHT_MAX) { + free (stats); eprintf ("Cannot find narenas_total\n"); return; } @@ -320,6 +322,8 @@ static void GH(jemalloc_get_bins)(RCore *core, const char *input) { } if (!GH(r_resolve_jemalloc)(core, "je_arena_bin_info", &bin_info)) { eprintf ("Error resolving je_arena_bin_info\n"); + free (ar); + free (b); return; } if (GH(r_resolve_jemalloc)(core, "je_arenas", &arenas)) { @@ -328,6 +332,8 @@ static void GH(jemalloc_get_bins)(RCore *core, const char *input) { for (;;) { r_core_read_at (core, arenas + i * sizeof (GHT), (ut8 *)&arena, sizeof (GHT)); if (!arena) { + free (ar); + free (b); break; } PRINTF_YA (" arenas[%d]: ", i++); diff --git a/libr/debug/p/debug_windbg.c b/libr/debug/p/debug_windbg.c index 6150eb9dc5..aaa8be4dbc 100644 --- a/libr/debug/p/debug_windbg.c +++ b/libr/debug/p/debug_windbg.c @@ -87,7 +87,6 @@ static RDebugReasonType r_debug_windbg_wait(RDebug *dbg, int pid) { reason = R_DEBUG_REASON_INT; break; } - free (pkt); } free (pkt); return reason; diff --git a/libr/io/p/io_windbg.c b/libr/io/p/io_windbg.c index 18867e7a5f..303bfd9a30 100644 --- a/libr/io/p/io_windbg.c +++ b/libr/io/p/io_windbg.c @@ -25,9 +25,6 @@ static bool __plugin_open(RIO *io, const char *file, bool many) { } static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { - void *io_ctx; - WindCtx *ctx; - if (!__plugin_open (io, file, 0)) { return NULL; } @@ -37,20 +34,18 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { return NULL; } - io_ctx = iob_open (file + 9); + void *io_ctx = iob_open (file + 9); if (!io_ctx) { eprintf ("Could not open the pipe\n"); return NULL; } - eprintf ("Opened pipe %s with fd %p\n", file+9, io_ctx); - - ctx = windbg_ctx_new (io_ctx); + eprintf ("Opened pipe %s with fd %p\n", file + 9, io_ctx); + WindCtx *ctx = windbg_ctx_new (io_ctx); if (!ctx) { eprintf ("Failed to initialize windbg context\n"); return NULL; } - return r_io_desc_new (&r_io_plugin_windbg, -1, file, true, mode, ctx); } @@ -58,7 +53,6 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { if (!fd) { return -1; } - if (windbg_get_target (fd->data)) { ut64 va; if (!windbg_va_to_pa (fd->data, io->off, &va)) { @@ -66,7 +60,6 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { } return windbg_write_at_phys (fd->data, buf, va, count); } - return windbg_write_at (fd->data, buf, io->off, count); }