From 613e6e2f9cb731de3e3975559349605c4e43e26f Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 3 Apr 2014 23:05:52 +0200 Subject: [PATCH] Fix invalid free and r2 -hh help --- binr/radare2/radare2.c | 59 ++++++++++++++++++++++------------------- doc/fortunes | 1 + libr/anal/var.c | 4 +-- libr/bin/bin.c | 24 ++++++----------- libr/core/p/core_test.c | 38 ++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 libr/core/p/core_test.c diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index 3033c5187b..2f3c7e1406 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -103,12 +103,15 @@ static int main_help(int line) { " system "R2_PREFIX"/share/radare2/radare2rc\n" " user ~/.radare2rc ${RHOMEDIR}/radare2/radare2rc\n" " file ${filename}.r2\n" + "Plugins:\n" + " plugins "R2_PREFIX"/lib/radare2/last\n" + " user ~/.config/radare2/plugins\n" + " LIBR_PLUGINS "R2_PREFIX"/lib/radare2/"R2_VERSION"\n" "Environment:\n" - " RHOMEDIR ~/.config/radare2\n" - " RCFILE ~/.radare2rc (user preferences, batch script)\n" + " RHOMEDIR ~/.config/radare2\n" // TODO: rename to RHOME R2HOME? + " RCFILE ~/.radare2rc (user preferences, batch script)\n" // TOO GENERIC " MAGICPATH "R_MAGIC_PATH"\n" " R_DEBUG if defined, show error messages and crash signal\n" - " LIBR_PLUGINS "R2_PREFIX"/lib/radare2/"R2_VERSION"\n" " VAPIDIR path to extra vapi directory\n" ); return 0; @@ -262,31 +265,31 @@ int main(int argc, char **argv, char **envp) { case 'n': run_anal = 0; break; case 'N': run_rc = 0; break; case 'p': - if (*optarg == '-') { - char *path, repath[128]; - snprintf (repath, sizeof (repath), - R2_HOMEDIR"/projects/%s.d", optarg+1); - path = r_str_home (repath); - if (r_file_exists (path)) { - if (r_file_rmrf (path) == R_FALSE) { - eprintf ("Unable to recursively remove %s\n", path); - free (path); - return 1; - } - path [strlen (path)-2] = 0; - if (r_file_rm (path) == R_FALSE) { - eprintf ("Unable to remove %s\n", path); - free (path); - return 1; - } - free (path); - return 0; - } - eprintf ("Can't find project '%s'\n", optarg+1); - return 1; - } else r_config_set (r.config, "file.project", optarg); - break; - case 'P': patchfile = optarg; break; + if (*optarg == '-') { + char *path, repath[128]; + snprintf (repath, sizeof (repath), + R2_HOMEDIR"/projects/%s.d", optarg+1); + path = r_str_home (repath); + if (r_file_exists (path)) { + if (r_file_rmrf (path) == R_FALSE) { + eprintf ("Unable to recursively remove %s\n", path); + free (path); + return 1; + } + path [strlen (path)-2] = 0; + if (r_file_rm (path) == R_FALSE) { + eprintf ("Unable to remove %s\n", path); + free (path); + return 1; + } + free (path); + return 0; + } + eprintf ("Can't find project '%s'\n", optarg+1); + return 1; + } else r_config_set (r.config, "file.project", optarg); + break; + case 'P': patchfile = optarg; break; case 'q': r_config_set (r.config, "scr.interactive", "false"); r_config_set (r.config, "scr.prompt", "false"); diff --git a/doc/fortunes b/doc/fortunes index b47489e501..46aac07787 100644 --- a/doc/fortunes +++ b/doc/fortunes @@ -215,3 +215,4 @@ EXPLICIT CONTENT bindings are mostly powered by tears In Soviet Russia, Radare have documentation Initial frame selected; you cannot go up. +unk, unk, unk, unk diff --git a/libr/anal/var.c b/libr/anal/var.c index 9e6959a50d..ac3536adf3 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -8,8 +8,8 @@ // Use sdb_vars ? #define DB a->sdb_fcns -#define EXISTS(x,y...) snprintf (key, sizeof(key)-1,x,##y),sdb_exists(DB,key) -#define SETKEY(x,y...) snprintf (key, sizeof (key)-1, x,##y); +#define EXISTS(x,y...) snprintf (key, sizeof (key)-1, x, ##y), sdb_exists(DB,key) +#define SETKEY(x,y...) snprintf (key, sizeof (key)-1, x, ##y); // DUPPED FUNCTIONALITY // kind = char? 'a'rg 'v'var (local, in frame), 'A' fast arg, register R_API int r_anal_fcn_var_add (RAnal *a, ut64 fna, const char kind, int scope, ut32 index, const char *name, const char *type) { diff --git a/libr/bin/bin.c b/libr/bin/bin.c index 396845ba68..8b0d3b497c 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -195,21 +195,15 @@ static void delete_bin_items (RBinObject *o) { r_list_free (o->lines); free (o->info); - //free (o->binsym); o->baddr = 0; o->boffset = 0; o->size = 0; - //o->binsym = NULL; - if (o->binsym != NULL) { - ut32 i = 0; - for (i=0; ibinsym[i]); - o->binsym[i] = NULL; - } - free (o->binsym);//, 0, sizeof (o->binsym)); - //o->binsym = NULL; + ut32 i = 0; + for (i=0; ibinsym[i]); + o->binsym[i] = NULL; } o->entries = NULL; o->fields = NULL; @@ -441,12 +435,10 @@ static void r_bin_free_items(RBin *bin) { RBINLISTFREE (o->classes); free (o->info); o->info = NULL; - - if (o->binsym) - for (i=0; ibinsym[i]); - o->binsym[i] = NULL; - } + for (i=0; ibinsym[i]); + o->binsym[i] = NULL; + } if (a->curplugin && a->curplugin->destroy) a->curplugin->destroy (a); else free (a->buf); diff --git a/libr/core/p/core_test.c b/libr/core/p/core_test.c new file mode 100644 index 0000000000..1730b08278 --- /dev/null +++ b/libr/core/p/core_test.c @@ -0,0 +1,38 @@ +/* radare - LGPL - Copyright 2014 - pancake */ +#if 0 +gcc -o core_test.so -fPIC `pkg-config --cflags --libs r_core` core_test.c -shared +mkdir -p ~/.config/radare2/plugins +mv core_test.so ~/.config/radare2/plugins +#endif + +#include +#include +#include +#include +#include +#include +#include + +#undef R_API +#define R_API static +#undef R_IPI +#define R_IPI static + +static int r_cmd_test_call() { + eprintf ("Dummy!\n"); + return R_FALSE; +} + +RCorePlugin r_core_plugin_test = { + .name = "test", + .desc = "lalallala", + .license = "Apache", + .call = r_cmd_test_call, +}; + +#ifndef CORELIB +struct r_lib_struct_t radare_plugin = { + .type = R_LIB_TYPE_CORE, + .data = &r_core_plugin_test +}; +#endif