Fix memleaks in zignatures and update spp

This commit is contained in:
pancake 2016-12-19 21:39:30 +01:00
parent 1a05aecaa4
commit 1facb46ab6
4 changed files with 33 additions and 21 deletions

View File

@ -54,8 +54,7 @@ static bool signatureExists(RSign *sig, RSignItem *item) {
R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const char *arg) { R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const char *arg) {
int len; int len;
char *data = NULL, *ptr; char *data = NULL, *ptr;
RSignItem *si; // TODO: like in r_search.. we need r_sign_item_new () RSignItem *si = NULL;
// TODO: but..we need to use a pool here..
if (!name || !arg || !anal) { if (!name || !arg || !anal) {
return false; return false;
} }
@ -76,6 +75,7 @@ R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
if (!signatureExists (sig, si)) { if (!signatureExists (sig, si)) {
if (!r_list_append (sig->items, si)) { if (!r_list_append (sig->items, si)) {
r_sign_item_free (si); r_sign_item_free (si);
si = NULL;
} else { } else {
sig->s_func++; sig->s_func++;
} }
@ -86,6 +86,7 @@ R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
case R_SIGN_BODY: // function body case R_SIGN_BODY: // function body
if (!(data = r_anal_strmask (anal, arg))) { if (!(data = r_anal_strmask (anal, arg))) {
r_sign_item_free (si); r_sign_item_free (si);
si = NULL;
break; break;
} }
len = strlen (data) + 4; // \xf0 len = strlen (data) + 4; // \xf0
@ -94,6 +95,7 @@ R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
if (!si->bytes || !si->mask) { if (!si->bytes || !si->mask) {
eprintf ("Cannot malloc\n"); eprintf ("Cannot malloc\n");
r_sign_item_free (si); r_sign_item_free (si);
si = NULL;
break; break;
} }
si->size = r_hex_str2binmask (data, si->bytes, si->mask); si->size = r_hex_str2binmask (data, si->bytes, si->mask);
@ -110,6 +112,7 @@ R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
} else if (type == R_SIGN_BODY) { } else if (type == R_SIGN_BODY) {
sig->s_func++; sig->s_func++;
} }
si = NULL;
} }
} }
break; break;
@ -120,8 +123,8 @@ R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
si = NULL; si = NULL;
break; break;
} }
free (si);
free (data); free (data);
return false; return false;
} }
@ -130,15 +133,17 @@ R_API void r_sign_list(RSign *sig, int rad, int json) {
int i; int i;
RListIter *iter; RListIter *iter;
RSignItem *si; RSignItem *si;
if (!r_list_empty (sig->items)) if (!r_list_empty (sig->items)) {
sig->cb_printf ("zp-\n"); sig->cb_printf ("zp-\n");
}
r_list_foreach (sig->items, iter, si) { r_list_foreach (sig->items, iter, si) {
sig->cb_printf ("z%c %s ", si->type, si->name); sig->cb_printf ("z%c %s ", si->type, si->name);
for (i=0; i<si->size; i++){ for (i = 0; i < si->size; i++){
if (!si->mask[i]) // This is a mask if (!si->mask[i]) { // This is a mask
sig->cb_printf (".."); sig->cb_printf ("..");
else } else {
sig->cb_printf ("%02x", si->bytes[i]); sig->cb_printf ("%02x", si->bytes[i]);
}
} }
sig->cb_printf ("\n"); sig->cb_printf ("\n");
} }

View File

@ -48,6 +48,9 @@ R_API RMemoryPool *r_mem_pool_free(RMemoryPool *pool) {
} }
R_API void* r_mem_pool_alloc(RMemoryPool *pool) { R_API void* r_mem_pool_alloc(RMemoryPool *pool) {
if (!pool) {
return NULL;
}
if (pool->ncount >= pool->poolsize) { if (pool->ncount >= pool->poolsize) {
if (++pool->npool >= pool->poolcount) { if (++pool->npool >= pool->poolcount) {
eprintf ("FAIL: Cannot allocate more memory in the pool\n"); eprintf ("FAIL: Cannot allocate more memory in the pool\n");

View File

@ -104,16 +104,19 @@ TAG_CALLBACK(spp_sub)
char *eq = strchr(buf, ' '); char *eq = strchr(buf, ' ');
char *var; char *var;
int ret = 0; int ret = 0;
if (!echo[ifl]) return 0; if (!echo[ifl]) {
return 0;
}
if (eq) { if (eq) {
*eq = '\0'; *eq = '\0';
var = spp_var_get(buf); var = spp_var_get (buf);
if (var == NULL) ret = 0; ret = var? atoi (var): 0;
else ret = atoi(var); ret -= atoi (eq + 1);
ret -= atoi(eq+1); r_sys_setenv (buf, eq + 1);
r_sys_setenv(buf, eq + 1); } else {
} else { /* syntax error */ } /* syntax error */
return 0; }
return ret;
} }
// XXX This method needs some love // XXX This method needs some love

View File

@ -152,7 +152,7 @@ retry:
delta = strlen (tag_post); delta = strlen (tag_post);
/* (pre) tag */ /* (pre) tag */
ptr = strstr (buf, tag_pre); ptr = tag_pre? strstr (buf, tag_pre): NULL;
if (ptr) { if (ptr) {
D printf ("==> 0.0 (%s)\n", ptr); D printf ("==> 0.0 (%s)\n", ptr);
incmd = 1; incmd = 1;
@ -177,15 +177,16 @@ retry:
if (ptrr < ptr2) { if (ptrr < ptr2) {
char *p = strdup (ptr2 + 2); char *p = strdup (ptr2 + 2);
char *s = spp_run_str (ptrr + strlen (tag_pre), NULL); char *s = spp_run_str (ptrr + strlen (tag_pre), NULL);
D fprintf (stderr, "strcpy(%s)(%s)\n",ptrr, s); D fprintf (stderr, "strcpy(%s)(%s)\n", ptrr, s);
strcpy (ptrr, s); strcpy (ptrr, s);
free (s); free (s);
ptr[-2] = tag_pre[0]; // XXX -2 check underflow? ptr[-2] = tag_pre[0]; // XXX -2 check underflow?
D fprintf(stderr, "strcat(%s)(%s)\n",ptrr, p); D fprintf (stderr, "strcat(%s)(%s)\n", ptrr, p);
strcat(ptrr, p); strcat (ptrr, p);
buf = ptr-2; buf = ptr - 2;
D fprintf(stderr, "CONTINUE (%s)\n", buf); D fprintf (stderr, "CONTINUE (%s)\n", buf);
free (p);
ptrr = NULL; ptrr = NULL;
goto retry; goto retry;
} }