* Use null fot unsupported plugins

* Fix startup segfault in r_reg doublefree
This commit is contained in:
pancake 2011-10-08 23:39:06 +02:00
parent ce1d0e9975
commit c7cced5c67
15 changed files with 32 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009 */
/* radare - LGPL - Copyright 2009-2011 */
/* nibble<.ds@gmail.com> */
#include <string.h>
@ -10,14 +10,10 @@
#include "x86/x86im/x86im.h"
static const char *gpr8[] = {
"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" };
static const char *gpr8b[] = {
"spl", "bpl", "sil", "dil" };
static const char *gpr16[] = {
"ax", "cx", "dx", "bx", "sp", "bp", "si", "di" };
static const char *gpr32[] = {
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" };
static const char *gpr8[] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" };
static const char *gpr8b[] = { "spl", "bpl", "sil", "dil" };
static const char *gpr16[] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di" };
static const char *gpr32[] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" };
static const char *gpr64[] = {
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" };

View File

@ -142,6 +142,8 @@ R_API int r_asm_add(RAsm *a, RAsmPlugin *foo) {
RListIter *iter;
RAsmPlugin *h;
// TODO: cache foo->name length and use memcmp instead of strcmp
if (!foo->name)
return R_FALSE;
if (foo->init)
foo->init (a->user);
r_list_foreach (a->plugins, iter, h)

View File

@ -92,8 +92,8 @@ LIB=lib${NAME}
LIBAR=${LIB}.${EXT_AR}
LIBSO=${LIB}.${EXT_SO}
ifeq (${OSTYPE},android)
libname=-shared -o ${LDFLAGS_SONAME}$1.${EXT_SO}
libname=-shared -o $1.${EXT_SO} ${LDFLAGS_SONAME}$1.${EXT_SO}
else
libname=-shared -o ${LDFLAGS_SONAME}$1.${EXT_SO}.${LIBVERSION}
libname=-shared -o $1.${EXT_SO} ${LDFLAGS_SONAME}$1.${EXT_SO}.${LIBVERSION}
endif

View File

@ -67,6 +67,7 @@ R_API int r_debug_plugin_list(RDebug *dbg) {
}
R_API int r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) {
if (!foo->name) return R_FALSE;
list_add_tail (&(foo->list), &(dbg->plugins));
return R_TRUE;
}

View File

@ -94,7 +94,7 @@ static RIODesc *__open(struct r_io_t *io, const char *pathname, int rw, int mode
struct r_io_plugin_t r_io_plugin_http = {
.name = "http",
.desc = "http get ( http://www.radare.org/ )",
.desc = "http get (http://radare.org/)",
.open = __open,
.close = __close,
.read = __read,

View File

@ -248,7 +248,7 @@ static int __system(struct r_io_t *io, RIODesc *fd, const char *cmd) {
// TODO: rename ptrace to io_mach .. err io.ptrace ??
struct r_io_plugin_t r_io_plugin_mach = {
.name = "mach",
.desc = "mach debug io",
.desc = "mach debugger io plugin (mach://pid)",
.open = __open,
.close = __close,
.read = __read,

View File

@ -84,7 +84,7 @@ static RIODesc *__open(struct r_io_t *io, const char *pathname, int rw, int mode
struct r_io_plugin_t r_io_plugin_malloc = {
.name = "malloc",
.desc = "memory allocation ( malloc://size-in-bytes )",
.desc = "memory allocation (malloc://1024)",
.open = __open,
.close = __close,
.read = __read,

View File

@ -144,8 +144,7 @@ struct r_io_plugin_t r_io_plugin_procpid = {
};
#else
struct r_io_plugin_t r_io_plugin_procpid = {
.name = "procpid",
.desc = "proc/pid/mem io (NOT SUPPORTED FOR THIS PLATFORM)",
.name = NULL
};
#endif

View File

@ -179,8 +179,7 @@ struct r_io_plugin_t r_io_plugin_ptrace = {
};
#else
struct r_io_plugin_t r_io_plugin_ptrace = {
.name = "ptrace",
.desc = "ptrace io (NOT SUPPORTED FOR THIS PLATFORM)",
.name = NULL
};
#endif

View File

@ -125,8 +125,7 @@ struct r_io_plugin_t r_io_plugin_w32dbg = {
};
#else
struct r_io_plugin_t r_io_plugin_w32dbg = {
.name = "w32dbg",
.desc = "w32dbg io (NOT SUPPORTED FOR THIS PLATFORM)",
.name = NULL
};
#endif

View File

@ -29,6 +29,8 @@ R_API int r_io_plugin_init(RIO *io) {
INIT_LIST_HEAD (&io->io_list);
for (i=0; io_static_plugins[i]; i++) {
if (!io_static_plugins[i]->name)
continue;
static_plugin = R_NEW (RIOPlugin);
memcpy (static_plugin, io_static_plugins[i], sizeof (RIOPlugin));
r_io_plugin_add (io, static_plugin);

View File

@ -123,8 +123,8 @@ R_API int r_lib_dl_check_filename(const char *file) {
R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol) {
RLibHandler *h = plugin->handler;
if (h && h->constructor != NULL)
return h->constructor(plugin, h->user, symbol->data);
if (h && h->constructor)
return h->constructor (plugin, h->user, symbol->data);
return R_FAIL;
}
@ -167,7 +167,7 @@ static int samefile(const char *a, const char *b) {
len = strlen (ptr+1) + 1;
memmove (ptr, ptr+1, len);
}
} while(ptr);
} while (ptr);
do {
ptr = strstr(sb, "//");
if (ptr) {
@ -187,7 +187,7 @@ R_API int r_lib_open(RLib *lib, const char *file) {
RLibPlugin *p;
RListIter *iter;
RLibStruct *stru;
void * handler;
void *handler;
int ret;
/* ignored by filename */
@ -317,6 +317,7 @@ R_API void r_lib_list(RLib *lib) {
#endif
//printf("Loaded plugins:\n");
r_list_foreach (lib->plugins, iter, p) {
printf(" %5s %p %s \n", r_lib_types_get(p->type), p->handler->destructor, p->file);
printf (" %5s %p %s \n", r_lib_types_get (p->type),
p->handler->destructor, p->file);
}
}

View File

@ -10,12 +10,12 @@ STATIC_OBJS=$(subst ..,p/..,$(subst parse_,p/parse_,$(STATIC_OBJ)))
OBJ=parse.o ${STATIC_OBJS}
bins:
cd t && ${MAKE} all
@cd t && ${MAKE} all
pre:
@if [ ! -e libr_parse.${EXT_SO} ]; then rm -f ${STATIC_OBJS} ; fi
plugins:
cd p && ${MAKE} all
@cd p && ${MAKE} all
include ../rules.mk

View File

@ -9,7 +9,7 @@ CFLAGS+=-DCORELIB
foo: all
ALL_TARGETS=
ARCHS=x86_pseudo.mk mreplace.mk
ARCHS=att2intel.mk x86_pseudo.mk mreplace.mk
include $(ARCHS)
all: ${ALL_TARGETS}

View File

@ -53,7 +53,7 @@ R_API void r_reg_free_internal(RReg *reg) {
int i;
for (i=0; i<R_REG_TYPE_LAST; i++) {
r_list_destroy (reg->regset[i].regs);
reg->regset[i].regs = NULL;
R_LIST_NEW (reg->regset[i].regs, r_reg_item_free);
}
}
@ -187,8 +187,10 @@ R_API int r_reg_set_profile_string(RReg *reg, const char *str) {
else if (word>3) {
r_reg_set_word (item, word, buf);
if (item->name != NULL) {
r_list_append (reg->regset[item->type].regs, item);
item = r_reg_item_new ();
if (reg->regset[item->type].regs) {
r_list_append (reg->regset[item->type].regs, item);
item = r_reg_item_new ();
} else eprintf ("REGSET is null wtf\n");
}
}
chidx = word = 0;