Implement support for >- (pipe to editor)

Fix another race condition in the build system
Fix many null deref reported by clang-analyzer
Assume -w when running r2 with -d
This commit is contained in:
pancake 2012-08-13 17:42:25 +02:00
parent f9795e03f9
commit e365b90d5f
21 changed files with 48 additions and 16 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;

View File

@ -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)))

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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));

View File

@ -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++;

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
/* 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;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2011-2012 - pancake */
#include <r_util.h>
#include <stdbool.h>
@ -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)))