diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index 5f4d5fb70e..dac010b0dc 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -2782,7 +2782,8 @@ static void fill_exports_list(struct MACH0_(obj_t) *bin, const char *name, ut64 const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { struct symbol_t *symbols; size_t i, j, s, symbols_size, symbols_count; - ut32 to, from; + ut32 to = UT32_MAX; + ut32 from = UT32_MAX; r_return_val_if_fail (bin, NULL); if (bin->symbols_cache) { @@ -2812,7 +2813,7 @@ const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { /* parse dynamic symbol table */ symbols_count = (bin->dysymtab.nextdefsym + \ bin->dysymtab.nlocalsym + \ - bin->dysymtab.nundefsym ); + bin->dysymtab.nundefsym); symbols_count += bin->nsymtab; ut64 tmp = symbols_count + 1; if (SZT_MUL_OVFCHK (symbols_count + 1, 2)) { @@ -2994,9 +2995,12 @@ static void assign_export_symbol_t(struct MACH0_(obj_t) *bin, const char *name, } const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin) { + r_return_val_if_fail (bin, NULL); struct symbol_t *symbols; - int j, s, stridx, symbols_size, symbols_count; - ut32 to, from, i; + int j = 0, s, stridx, symbols_size, symbols_count; + ut32 to = UT32_MAX; + ut32 from = UT32_MAX; + ut32 i; if (bin->symbols) { return bin->symbols; @@ -3007,7 +3011,6 @@ const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin) { return NULL; } - r_return_val_if_fail (bin, NULL); int n_exports = walk_exports (bin, NULL, NULL); symbols_count = n_exports; diff --git a/libr/core/p/core_sixref.c b/libr/core/p/core_sixref.c index 2c68f0f029..4ff5dacb88 100644 --- a/libr/core/p/core_sixref.c +++ b/libr/core/p/core_sixref.c @@ -216,7 +216,7 @@ static void siguza_xrefs_chunked(RCore *core, ut64 search, int lenbytes) { addref (core, addr, addr + off, R_ANAL_REF_TYPE_CODE); // r_cons_printf ("ax 0x%"PFMT64x" 0x%"PFMT64x"\n", addr + off, addr); } else if (addr + off == search) { - const char *cond; + const char *cond = "al"; switch(v & 0xf) { case 0x0: cond = "eq"; break; @@ -236,7 +236,7 @@ static void siguza_xrefs_chunked(RCore *core, ut64 search, int lenbytes) { case 0xe: cond = "al"; break; case 0xf: cond = "nv"; break; } - r_cons_printf("%#"PFMT64x": b.%s %#"PFMT64x"\n", addr, cond, search); + r_cons_printf ("%#"PFMT64x": b.%s %#"PFMT64x"\n", addr, cond, search); } } else if ((v & 0x7e000000) == 0x34000000) // cbz and cbnz diff --git a/libr/main/rabin2.c b/libr/main/rabin2.c index a01d1c7d9a..63ccd5b805 100644 --- a/libr/main/rabin2.c +++ b/libr/main/rabin2.c @@ -278,58 +278,57 @@ static int rabin_dump_symbols(RBin *bin, int len) { } static bool __dumpSections(RBin *bin, const char *scnname, const char *output, const char *file, bool raw) { - RList *sections; RListIter *iter; RBinSection *section; - ut8 *buf; - char *ret; - int r; - - if (!(sections = r_bin_get_sections (bin))) { + RList *sections = r_bin_get_sections (bin); + if (!sections || r_list_empty (sections)) { + R_LOG_WARN ("No sections to dump"); return false; } r_list_foreach (sections, iter, section) { - if (r_str_glob (section->name, scnname)) { - if (!(buf = malloc (section->size))) { - return false; - } - if ((section->size * 2) + 1 < section->size) { - free (buf); - return false; - } - if (!(ret = malloc (section->size*2+1))) { - free (buf); - return false; - } - if (section->paddr > r_buf_size (bin->cur->buf) || - section->paddr + section->size > r_buf_size (bin->cur->buf)) { - free (buf); - free (ret); - return false; - } - r = r_buf_read_at (bin->cur->buf, section->paddr, - buf, section->size); - if (r < 1) { - free (buf); - free (ret); - return false; - } - //it does mean the user specified an output file - if (strcmp (output, file)) { - r_file_dump (output, buf, section->size, 0); - } else { - if (raw) { - write (1, buf, section->size); - } else { - r_hex_bin2str (buf, section->size, ret); - printf ("%s\n", ret); - } - } + if (!r_str_glob (section->name, scnname)) { + continue; + } + const size_t ss = section->size; + if ((ss * 2) + 1 < ss) { + return false; + } + ut8 *buf = malloc (ss); + char *ret = malloc (ss * 2 + 1); + if (R_UNLIKELY (!buf || !ret)) { free (buf); free (ret); - break; + return false; } + if (section->paddr > r_buf_size (bin->cur->buf) || + section->paddr + ss > r_buf_size (bin->cur->buf)) { + free (buf); + free (ret); + return false; + } + int r = r_buf_read_at (bin->cur->buf, section->paddr, buf, ss); + if (r < 1) { + free (buf); + free (ret); + return false; + } + //it does mean the user specified an output file + if (strcmp (output, file)) { + r_file_dump (output, buf, ss, 0); + } else { + if (raw) { + if (write (1, buf, ss) != ss) { + R_LOG_WARN ("write truncated"); + } + } else { + r_hex_bin2str (buf, ss, ret); + printf ("%s\n", ret); + } + } + free (buf); + free (ret); + break; } return true; } diff --git a/sys/profiling.sh b/sys/profiling.sh new file mode 100755 index 0000000000..e7f51b86c5 --- /dev/null +++ b/sys/profiling.sh @@ -0,0 +1,4 @@ +#!/bin/sh +export CFLAGS="-pg -g -O1 -no-pie" +export LDFLAGS="$CFLAGS" +sys/install.sh