From 5ffc549708d9683ce5e58a8d3c1ed6c1b3d24c28 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 23 Aug 2022 17:43:34 +0200 Subject: [PATCH] Fix last covs --- libr/anal/meta.c | 5 +++-- libr/bin/p/bin_rel.c | 18 ++++++++++-------- libr/core/cmd.c | 32 ++++++++++++++++---------------- libr/fs/p/fs_zip.c | 16 ++++++++++------ libr/main/rasm2.c | 5 ++--- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/libr/anal/meta.c b/libr/anal/meta.c index 9b90298933..4e77ea7ded 100644 --- a/libr/anal/meta.c +++ b/libr/anal/meta.c @@ -4,8 +4,7 @@ #include static bool item_matches_filter(RAnalMetaItem *item, RAnalMetaType type, R_NULLABLE const RSpace *space) { - return (type == R_META_TYPE_ANY || item->type == type) - && (!space || item->space == space); + return (type == R_META_TYPE_ANY || item->type == type) && (!space || item->space == space); } typedef struct { @@ -550,8 +549,10 @@ beach: pj_end (pj); r_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); + pj = NULL; } } + pj_free (pj); } R_API void r_meta_print_list_all(RAnal *a, int type, int rad, const char *tq) { diff --git a/libr/bin/p/bin_rel.c b/libr/bin/p/bin_rel.c index a579e1b153..9ebe29e040 100644 --- a/libr/bin/p/bin_rel.c +++ b/libr/bin/p/bin_rel.c @@ -145,12 +145,16 @@ static int load_reloc_table(RelReloc *out, RBuffer *buf, ut64 addr) { r_buf_seek (buf, addr, R_BUF_SET); int i; for (i = 0; i < MAX_RELOC_COUNT; i++) { - RelReloc reloc; - if (r_buf_fread (buf, (void *)&reloc, "SccI", 1) == -1 || reloc.type == R_RVL_STOP) { + RelReloc reloc = {0}; + if (r_buf_fread (buf, (void *)&reloc, "SccI", 1) == -1) { + break; + } + if (reloc.type == R_RVL_STOP) { break; } if (out) { - *(out++) = reloc; + *out = reloc; + out++; } } if (i == MAX_RELOC_COUNT) { @@ -160,7 +164,7 @@ static int load_reloc_table(RelReloc *out, RBuffer *buf, ut64 addr) { } static bool vread_at_be32(RBin *b, ut32 vaddr, ut32 *out) { - ut8 buf[4]; + ut8 buf[4] = {0}; if (!b->iob.read_at (b->iob.io, vaddr, (void *)&buf, sizeof (buf))) { return false; } @@ -485,14 +489,12 @@ static RBinReloc *patch_reloc(RBin *b, const LoadedRel *rel, const RelReloc *rel case R_RVL_NONE: case R_RVL_SECT: return NULL; - case R_PPC_ADDR32: size = 4; value = S + A; break; case R_PPC_ADDR24: size = 4; value = set_low24(value, (S + A) >> 2); break; case R_PPC_REL24: size = 4; value = set_low24(value, (S + A - P) >> 2); break; case R_PPC_ADDR16_LO: size = 2; value = set_half16(value, lo(S + A)); break; case R_PPC_ADDR16_HI: size = 2; value = set_half16(value, hi(S + A)); break; case R_PPC_ADDR16_HA: size = 2; value = set_half16(value, ha(S + A)); break; - default: R_LOG_ERROR ("REL: Unsupported reloc type %d", reloc->type); return NULL; @@ -521,9 +523,9 @@ static RBinReloc *patch_reloc(RBin *b, const LoadedRel *rel, const RelReloc *rel return NULL; } switch (size) { - case 1: ret->type = R_BIN_RELOC_8; break; + // UNREACHABLE case 1: ret->type = R_BIN_RELOC_8; break; case 2: ret->type = R_BIN_RELOC_16; break; - case 3: ret->type = R_BIN_RELOC_24; break; + // UNREACHABLE case 3: ret->type = R_BIN_RELOC_24; break; case 4: ret->type = R_BIN_RELOC_32; break; default: R_LOG_DEBUG ("Cannot convert reloc of size %d to RBinReloc", size); diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 021f087e09..16e396f1cf 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -2617,7 +2617,7 @@ static int cmd_panels(void *data, const char *input) { if (r) { free (r); } else { - eprintf ("Cannot open file (%s)\n", sp + 1); + R_LOG_ERROR ("Cannot open file (%s)", sp + 1); } } return false; @@ -4099,7 +4099,7 @@ escape_backtick: repeat_arroba: arroba = (ptr[0] && ptr[1] && ptr[2])? strchr (ptr + 2, '@'): NULL; if (!strncmp (ptr, "@@@", 3)) { // "@@@@" - eprintf ("Cannot iterate that much.\n"); + R_LOG_ERROR ("Cannot iterate that much"); goto fuji; } if (arroba) { @@ -4151,7 +4151,7 @@ repeat_arroba: } } else { // WAT DU - eprintf ("TODO: what do you expect for @. import offset from file maybe?\n"); + R_LOG_INFO ("TODO: what do you expect for @. import offset from file maybe?"); } } else if (ptr[0] && ptr[1] == ':' && ptr[2]) { switch (ptr[0]) { @@ -4176,7 +4176,7 @@ repeat_arroba: eprintf ("The current basic block has %d instructions\n", bb->ninstr); } } else { - eprintf ("Can't find a basic block for 0x%08"PFMT64x"\n", core->offset); + R_LOG_ERROR ("Can't find a basic block for 0x%08"PFMT64x, core->offset); } break; } @@ -4199,7 +4199,7 @@ repeat_arroba: } } } else { - eprintf ("cannot open '%s'\n", ptr + 3); + R_LOG_ERROR ("cannot open '%s'", ptr + 3); } break; case 'r': // "@r:" // regname @@ -4289,7 +4289,7 @@ repeat_arroba: r_core_block_read (core); } } else { - eprintf ("Invalid @v: syntax\n"); + R_LOG_ERROR ("Invalid @v: syntax"); } break; case 'x': // "@x:" // hexpairs @@ -4318,10 +4318,10 @@ repeat_arroba: } free (buf); } else { - eprintf ("cannot allocate\n"); + R_LOG_ERROR ("cannot allocate"); } } else { - eprintf ("Invalid @x: syntax\n"); + R_LOG_ERROR ("Invalid @x: syntax"); } break; case 'k': // "@k" @@ -4423,7 +4423,7 @@ ignore: if (isalpha ((ut8)ptr[1]) && !addr) { if (!r_flag_get (core->flags, ptr + 1)) { - eprintf ("Invalid address (%s)\n", ptr + 1); + R_LOG_ERROR ("Invalid address (%s)", ptr + 1); goto fail; } } else { @@ -4944,13 +4944,13 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ } break; case 0: - eprintf ("Nothing to repeat. Check @@@?\n"); + R_LOG_INFO ("Nothing to repeat. Check @@@?"); break; case '@': - eprintf ("I can't iterate that much!\n"); + R_LOG_WARN ("I can't iterate that much!"); break; default: - eprintf ("Invalid repeat type, Check @@@? for help\n"); + R_LOG_ERROR ("Invalid repeat type, Check @@@? for help"); break; } r_list_free (list); @@ -5098,7 +5098,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { free (ostr); return 0; case 0: - eprintf ("Nothing to repeat. Check @@?\n"); + R_LOG_ERROR ("Nothing to repeat. Check @@?"); break; case '?': // "@@?" r_core_cmd_help (core, help_msg_at_at); @@ -5289,7 +5289,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { r_core_seek (core, oseek, false); r_list_free (list); } else { - eprintf("Invalid for-each statement. Use @@=dbt[abs]\n"); + R_LOG_ERROR ("Invalid for-each statement. Use @@=dbt[abs]"); } break; case 'k': // "@@k" @@ -5372,7 +5372,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { free (buf); fclose (fd); } else { - eprintf ("cannot open file '%s' to read offsets\n", each + 1); + R_LOG_ERROR ("cannot open file '%s' to read offsets", each + 1); } } break; @@ -5529,7 +5529,7 @@ R_API int r_core_cmd(RCore *core, const char *cstr, bool log) { } if (!strncmp (cstr, "/*", 2)) { if (r_sandbox_enable (0)) { - eprintf ("This command is disabled in sandbox mode\n"); + R_LOG_ERROR ("This command is disabled in sandbox mode"); goto beach; // false } core->incomment = true; diff --git a/libr/fs/p/fs_zip.c b/libr/fs/p/fs_zip.c index 53a634a0d3..eb1fbaf930 100644 --- a/libr/fs/p/fs_zip.c +++ b/libr/fs/p/fs_zip.c @@ -84,6 +84,7 @@ static int fs_zip_read(RFSFile *file, ut64 addr, int len) { return ret; } #endif + free (abs_path); return -1; } @@ -102,13 +103,9 @@ static void append_file(RList *list, const char *name, int type, int time, ut64 r_list_append (list, fsf); } -static RList *fs_zip_dir(RFSRoot *root, const char *path, int view /*ignored*/) { - RList *list = r_list_new (); - if (!list) { - return NULL; - } +static RList *fs_zip_dir(RFSRoot *root, const char *path, R_UNUSED int view) { ut64 addr = 0; - RIOMap *map = root->iob.map_get_at(root->iob.io, addr); + RIOMap *map = root->iob.map_get_at (root->iob.io, addr); if (!map) { R_LOG_ERROR ("no map"); return NULL; @@ -124,24 +121,31 @@ static RList *fs_zip_dir(RFSRoot *root, const char *path, int view /*ignored*/) int res = root->iob.read_at (root->iob.io, 0, buf, buflen); if (res < 1) { R_LOG_ERROR ("io read problems"); + free (buf); return NULL; } // open dir and enumerate files zip_error_t error; zip_source_t *zs = zip_source_buffer_create (buf, buflen, 0, &error); if (!zs) { + free (buf); return NULL; } int _flags = 0; zip_t *za = zip_open_from_source (zs, _flags, &error); if (!za) { R_LOG_ERROR ("failed to open zip from source"); + free (buf); return NULL; } int num_entries = zip_get_num_files (za); int i; bool hasdir = false; bool hasfailed = false; + RList *list = r_list_new (); + if (!list) { + return NULL; + } for (i = 0; i < num_entries; i++) { struct zip_stat sb; zip_stat_init (&sb); diff --git a/libr/main/rasm2.c b/libr/main/rasm2.c index 7ab454c68f..16a9bb4347 100644 --- a/libr/main/rasm2.c +++ b/libr/main/rasm2.c @@ -759,8 +759,8 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { char *log_level = r_sys_getenv ("R2_LOG_LEVEL"); if (R_STR_ISNOTEMPTY (log_level)) { r_log_set_level (atoi (log_level)); - free (log_level); } + R_FREE (log_level); RAsmState *as = __as_new (); // TODO set addrbytes @@ -1084,8 +1084,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { len -= skip; usrstr[len] = 0; } - // XXX this is a wrong usage of endianness - if (!strncmp (usrstr, "0x", 2)) { + if (r_str_startswith (usrstr, "0x")) { memmove (usrstr, usrstr + 2, strlen (usrstr + 2) + 1); } if (rad) {