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) {
int len;
char *data = NULL, *ptr;
RSignItem *si; // TODO: like in r_search.. we need r_sign_item_new ()
// TODO: but..we need to use a pool here..
RSignItem *si = NULL;
if (!name || !arg || !anal) {
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 (!r_list_append (sig->items, si)) {
r_sign_item_free (si);
si = NULL;
} else {
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
if (!(data = r_anal_strmask (anal, arg))) {
r_sign_item_free (si);
si = NULL;
break;
}
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) {
eprintf ("Cannot malloc\n");
r_sign_item_free (si);
si = NULL;
break;
}
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) {
sig->s_func++;
}
si = NULL;
}
}
break;
@ -120,8 +123,8 @@ R_API bool r_sign_add(RSign *sig, RAnal *anal, int type, const char *name, const
si = NULL;
break;
}
free (si);
free (data);
return false;
}
@ -130,15 +133,17 @@ R_API void r_sign_list(RSign *sig, int rad, int json) {
int i;
RListIter *iter;
RSignItem *si;
if (!r_list_empty (sig->items))
if (!r_list_empty (sig->items)) {
sig->cb_printf ("zp-\n");
}
r_list_foreach (sig->items, iter, si) {
sig->cb_printf ("z%c %s ", si->type, si->name);
for (i=0; i<si->size; i++){
if (!si->mask[i]) // This is a mask
for (i = 0; i < si->size; i++){
if (!si->mask[i]) { // This is a mask
sig->cb_printf ("..");
else
} else {
sig->cb_printf ("%02x", si->bytes[i]);
}
}
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) {
if (!pool) {
return NULL;
}
if (pool->ncount >= pool->poolsize) {
if (++pool->npool >= pool->poolcount) {
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 *var;
int ret = 0;
if (!echo[ifl]) return 0;
if (!echo[ifl]) {
return 0;
}
if (eq) {
*eq = '\0';
var = spp_var_get(buf);
if (var == NULL) ret = 0;
else ret = atoi(var);
ret -= atoi(eq+1);
r_sys_setenv(buf, eq + 1);
} else { /* syntax error */ }
return 0;
var = spp_var_get (buf);
ret = var? atoi (var): 0;
ret -= atoi (eq + 1);
r_sys_setenv (buf, eq + 1);
} else {
/* syntax error */
}
return ret;
}
// XXX This method needs some love

View File

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