diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index 59d5a4924d..ccd065bc47 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -185,6 +185,7 @@ int main(int argc, char **argv) { int filelen = 0; r_config_set (r.config, "io.va", "false"); // implicit? r_config_set (r.config, "cfg.debug", "true"); + perms = R_IO_READ | R_IO_WRITE; if (optind>=argc) { eprintf ("No program given to -d\n"); return 1; diff --git a/libr/anal/diff.c b/libr/anal/diff.c index 8512aea368..fffb0908b7 100644 --- a/libr/anal/diff.c +++ b/libr/anal/diff.c @@ -153,6 +153,7 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { return (anal->cur->diff_fcn (anal, fcns, fcns2)); /* Compare functions with the same name */ + if (fcns) r_list_foreach (fcns, iter, fcn) { if (fcn->type != R_ANAL_FCN_TYPE_SYM || fcn->name == NULL) continue; diff --git a/libr/anal/fcn.c b/libr/anal/fcn.c index fed7fb6e44..73d51dbef6 100644 --- a/libr/anal/fcn.c +++ b/libr/anal/fcn.c @@ -440,7 +440,7 @@ R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *sig) { strcat(str, sig); /* Send whole definition to cparse */ - int yv, yylval; + int yv, yylval = 0; void *pParser = cdataParseAlloc(malloc); yy_scan_string(str); while ((yv = yylex()) != 0) { diff --git a/libr/anal/fcnstore.c b/libr/anal/fcnstore.c index f6a7c7a7ce..4665bb5f5e 100644 --- a/libr/anal/fcnstore.c +++ b/libr/anal/fcnstore.c @@ -82,6 +82,7 @@ R_API void r_listrange_del(RListRange *s, RAnalFunction *f) { } R_API void r_listrange_resize(RListRange *s, RAnalFunction *f, int newsize) { + if (!f) return; r_listrange_del (s, f); f->size = newsize; r_listrange_add (s, f); diff --git a/libr/anal/meta.c b/libr/anal/meta.c index cd7519bfc3..d235688642 100644 --- a/libr/anal/meta.c +++ b/libr/anal/meta.c @@ -101,6 +101,7 @@ R_API int r_meta_cleanup(RMeta *m, ut64 from, ut64 to) { if (from == 0LL && to == UT64_MAX) { RMeta *m2 = r_meta_new (); + if (!m2) return R_FALSE; r_list_free (m->data); m->data = m2->data; free (m2); diff --git a/libr/anal/type.c b/libr/anal/type.c index 0f9a214caf..b3334077ef 100644 --- a/libr/anal/type.c +++ b/libr/anal/type.c @@ -77,7 +77,7 @@ R_API RAnalType *r_anal_str_to_type(RAnal *a, const char* type) { R_API RAnalType *r_anal_type_loadfile(RAnal *a, const char *path) { FILE *cfile; int n; - int yv, yylval; + int yv, yylval = 0; char buf[4096]; void *pParser = cdataParseAlloc(malloc); diff --git a/libr/asm/asm.c b/libr/asm/asm.c index 4bf694ff4f..13c96028c4 100644 --- a/libr/asm/asm.c +++ b/libr/asm/asm.c @@ -370,7 +370,7 @@ R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, const char *hexstr) { return NULL; } ret = r_asm_mdisassemble (a, buf, (ut64)len); - if (a->ofilter) + if (ret && a->ofilter) r_parse_parse (a->ofilter, ret->buf_asm, ret->buf_asm); free (buf); return ret; diff --git a/libr/bin/bin.c b/libr/bin/bin.c index a94b5cc77e..c7b9afc72f 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -24,6 +24,7 @@ static void get_strings_range(RBinArch *arch, RList *list, int min, ut64 from, u eprintf ("WARNING: bin_strings buffer is too big\n"); return; } + if (arch->buf && arch->buf->buf) for (i = from; i < to; i++) { if ((IS_PRINTABLE (arch->buf->buf[i])) && \ matches < R_BIN_SIZEOF_STRINGS-1) { diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index 25e3d5d539..2899ef543c 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -971,8 +971,14 @@ struct r_bin_elf_symbol_t* Elf_(r_bin_elf_get_symbols)(struct Elf_(r_bin_elf_obj ret[ret_ctr].last = 0; ret_ctr++; } - if ((ret = realloc (ret, (ret_ctr + 1) * sizeof (struct r_bin_elf_symbol_t))) == NULL) + { + ut8 *p = realloc (ret, (ret_ctr+1)* sizeof (struct r_bin_elf_symbol_t)); + if (!p) { + free (ret); return NULL; + } + ret = (struct r_bin_elf_symbol_t *) p; + } ret[ret_ctr].last = 1; // ugly dirty hack :D break; } diff --git a/libr/bin/mangling/cxx/cp-demangle.c b/libr/bin/mangling/cxx/cp-demangle.c index 20c1233ee7..becb55582e 100644 --- a/libr/bin/mangling/cxx/cp-demangle.c +++ b/libr/bin/mangling/cxx/cp-demangle.c @@ -2224,6 +2224,7 @@ cplus_demangle_type (struct d_info *di) case 'n': /* decltype(nullptr) */ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]); + if (ret) di->expansion += ret->u.s_builtin.type->len; break; diff --git a/libr/bp/Makefile b/libr/bp/Makefile index 8e72c5f2f4..4812724b28 100644 --- a/libr/bp/Makefile +++ b/libr/bp/Makefile @@ -4,7 +4,8 @@ DEPS+=r_util CFLAGS+=-DCORELIB include ../config.mk -foo: libr_bp.${EXT_SO} libr_bp.${EXT_AR} plugins +foo: + for a in libr_bp.${EXT_SO} libr_bp.${EXT_AR} plugins ; do ${MAKE} $$a ; done include ${STATIC_BP_PLUGINS} STATIC_OBJS=$(subst ..,p/..,$(subst bp_,p/bp_,$(STATIC_OBJ))) diff --git a/libr/config/config.c b/libr/config/config.c index 24183eee68..bd99ef17a2 100644 --- a/libr/config/config.c +++ b/libr/config/config.c @@ -218,6 +218,7 @@ R_API RConfigNode *r_config_set_i(RConfig *cfg, const char *name, const ut64 i) if (i<1024) snprintf (buf, sizeof (buf), "%"PFMT64d"", i); else snprintf (buf, sizeof (buf), "0x%08"PFMT64x"", i); node = r_config_node_new (name, buf); + if (!node) return NULL; node->flags = CN_RW | CN_OFFT; node->i_value = i; r_hashtable_insert (cfg->ht, node->hash, node); diff --git a/libr/core/cmd.c b/libr/core/cmd.c index efcf69e7be..427de8f3de 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -482,7 +482,7 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { colon = strchr (icmd, ';'); if (colon) *colon = 0; - } + } else colon = NULL; if (rep>0) { while (*cmd>='0' && *cmd<='9') cmd++; @@ -635,17 +635,33 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd) { /* pipe console to file */ ptr = strchr (cmd, '>'); if (ptr) { + int use_editor = R_FALSE; + int ocolor = r_config_get_i (core->config, "scr.color"); /* r_cons_flush() handles interactive output (to the terminal) * differently (e.g. asking about too long output). This conflicts * with piping to a file. Disable it while piping. */ r_cons_set_interactive (R_FALSE); *ptr = '\0'; str = r_str_trim_head_tail (ptr+1+(ptr[1]=='>')); + if (!strcmp (str, "-")) { + use_editor = R_TRUE; + str = r_file_temp ("dumpedit"); + r_config_set (core->config, "scr.color", "false"); + } pipefd = r_cons_pipe_open (str, ptr[1]=='>'); ret = r_core_cmd_subst (core, cmd); r_cons_flush (); r_cons_pipe_close (pipefd); r_cons_set_last_interactive (); + if (use_editor) { + const char *editor = r_config_get (core->config, "cfg.editor"); + if (editor && *editor) { + r_sys_cmdf ("%s '%s'", editor, str); + } else eprintf ("No cfg.editor configured\n"); + r_config_set_i (core->config, "scr.color", ocolor); + r_file_rm (str); + free (str); + } return ret; } diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index 602f11706c..ad2a79d7b8 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -454,7 +454,7 @@ return 0; break; case 'z': { - char *p, *s = malloc (core->blocksize+1); + char *s = malloc (core->blocksize+1); int i, j; if (s) { memset (s, 0, core->blocksize); diff --git a/libr/core/file.c b/libr/core/file.c index 6e857471f6..971f32874c 100644 --- a/libr/core/file.c +++ b/libr/core/file.c @@ -34,7 +34,8 @@ R_API int r_core_file_reopen(RCore *core, const char *args) { r_core_file_close_fd (core, newpid); // TODO: in debugger must select new PID if (r_config_get_i (core->config, "cfg.debug")) { - newpid = core->file->fd->fd; + if (core->file && core->file->fd) + newpid = core->file->fd->fd; r_debug_select (core->dbg, newpid, newpid); } free (path); diff --git a/libr/core/vmenus.c b/libr/core/vmenus.c index b1fb917b4c..733ffb94f0 100644 --- a/libr/core/vmenus.c +++ b/libr/core/vmenus.c @@ -945,7 +945,7 @@ static ut64 addr = 0; static int option = 0; static void r_core_visual_anal_refresh (RCore *core) { - ut64 addr; + ut64 addr = core->offset; char old[1024]; old[0]='\0'; int cols = r_cons_get_size (NULL); diff --git a/libr/debug/p/libgdbwrap/gdbwrapper.c b/libr/debug/p/libgdbwrap/gdbwrapper.c index cf7af912dd..165783c90c 100644 --- a/libr/debug/p/libgdbwrap/gdbwrapper.c +++ b/libr/debug/p/libgdbwrap/gdbwrapper.c @@ -306,7 +306,7 @@ static void gdbwrap_populate_reg(gdbwrap_t *desc, char *packet) { { nextupacket = gdbwrap_extract_from_packet(nextpacket, packetcolon, NULL, GDBWRAP_SEP_COLON, sizeof(packetcolon)); - if (nextpacket == NULL) return; + if (nextpacket == NULL || !nextupacket) return; if (strlen (nextupacket) == 2) { ureg32 regvalue; uint8_t regnumber = gdbwrap_atoh(nextupacket, strlen(nextupacket)); diff --git a/libr/egg/lang.c b/libr/egg/lang.c index 832855dda8..9922229859 100644 --- a/libr/egg/lang.c +++ b/libr/egg/lang.c @@ -195,8 +195,8 @@ static char *get_end_frame_label(REgg *egg) { static void rcc_pusharg(REgg *egg, char *str) { REggEmit *e = egg->emit; - char buf[64], *p; - p = r_egg_mkvar (egg, buf, str, 0); + char buf[64], *p = r_egg_mkvar (egg, buf, str, 0); + if (!p) return; // TODO: free (ctxpush[context]); ctxpush[context] = strdup (p); // INDEX IT WITH NARGS OR CONTEXT?!? nargs++; diff --git a/libr/socket/socket.c b/libr/socket/socket.c index 4857d2d6a4..d1434835cb 100644 --- a/libr/socket/socket.c +++ b/libr/socket/socket.c @@ -452,8 +452,7 @@ R_API int r_socket_gets(RSocket *s, char *buf, int size) { } R_API RSocket *r_socket_new_from_fd (int fd) { - RSocket *s = R_NEW (RSocket); - s->is_ssl = 0; + RSocket *s = R_NEW0 (RSocket); s->fd = fd; return s; } diff --git a/libr/util/buf.c b/libr/util/buf.c index 13df589f9c..c3f794816f 100644 --- a/libr/util/buf.c +++ b/libr/util/buf.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2011 pancake */ +/* radare - LGPL - Copyright 2009-2012 - pancake */ #include "r_types.h" #include "r_util.h" @@ -28,6 +28,7 @@ R_API RBuffer *r_buf_new() { R_API RBuffer *r_buf_mmap (const char *file, int rw) { RBuffer *b = r_buf_new (); + if (!b) return NULL; b->mmap = r_file_mmap (file, rw); if (b->mmap && b->mmap->len>0) { b->buf = b->mmap->buf; diff --git a/libr/util/chmod.c b/libr/util/chmod.c index 3186311ae2..2dc907b998 100644 --- a/libr/util/chmod.c +++ b/libr/util/chmod.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2011 pancake */ +/* radare - LGPL - Copyright 2011-2012 - pancake */ #include #include @@ -141,6 +141,7 @@ static void recurse(const char *path, int rec, int (*fn)(const char *,int)) { cwd = agetcwd(); if (chdir (path) == -1) { eprintf ("chdir %s:", path); + free (cwd); return; } while ((d = readdir (dp)))