Use r_str_const to avoid dangling calling conventions in fcn->cc

This commit is contained in:
pancake 2017-05-04 14:51:05 +02:00
parent 028878f87a
commit 0ac3477662
7 changed files with 20 additions and 12 deletions

View File

@ -1296,7 +1296,7 @@ R_API int r_anal_fcn_add(RAnal *a, ut64 addr, ut64 size, const char *name, int t
append = 1; append = 1;
} }
fcn->addr = addr; fcn->addr = addr;
fcn->cc = r_anal_cc_default (a); fcn->cc = r_str_const (r_anal_cc_default (a));
fcn->bits = a->bits; fcn->bits = a->bits;
r_anal_fcn_set_size (fcn, size); r_anal_fcn_set_size (fcn, size);
free (fcn->name); free (fcn->name);

View File

@ -593,7 +593,7 @@ static int java_analyze_fns_from_buffer( RAnal *anal, ut64 start, ut64 end, int
ut64 length = buf_len - offset; ut64 length = buf_len - offset;
RAnalFunction *fcn = r_anal_fcn_new (); RAnalFunction *fcn = r_anal_fcn_new ();
fcn->cc = r_anal_cc_default (anal); fcn->cc = r_str_const (r_anal_cc_default (anal));
result = analyze_from_code_buffer ( anal, fcn, addr, buffer+offset, length ); result = analyze_from_code_buffer ( anal, fcn, addr, buffer+offset, length );
if (result == R_ANAL_RET_ERROR) { if (result == R_ANAL_RET_ERROR) {
eprintf ("Failed to parse java fn: %s @ 0x%04"PFMT64x"\n", fcn->name, fcn->addr); eprintf ("Failed to parse java fn: %s @ 0x%04"PFMT64x"\n", fcn->name, fcn->addr);
@ -643,7 +643,7 @@ static int java_analyze_fns( RAnal *anal, ut64 start, ut64 end, int reftype, int
(check_addr_less_start (method, end) || (check_addr_less_start (method, end) ||
check_addr_in_code (method, end))) { check_addr_in_code (method, end))) {
RAnalFunction *fcn = r_anal_fcn_new (); RAnalFunction *fcn = r_anal_fcn_new ();
fcn->cc = r_anal_cc_default (anal); fcn->cc = r_str_const (r_anal_cc_default (anal));
java_set_function_prototype (anal, fcn, method); java_set_function_prototype (anal, fcn, method);
result = analyze_from_code_attr (anal, fcn, method, loadaddr); result = analyze_from_code_attr (anal, fcn, method, loadaddr);
if (result == R_ANAL_RET_ERROR) { if (result == R_ANAL_RET_ERROR) {

View File

@ -490,7 +490,7 @@ static int core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth
eprintf ("Error: new (fcn)\n"); eprintf ("Error: new (fcn)\n");
return false; return false;
} }
fcn->cc = r_anal_cc_default (core->anal); fcn->cc = r_str_const (r_anal_cc_default (core->anal));
hint = r_anal_hint_get (core->anal, at); hint = r_anal_hint_get (core->anal, at);
if (hint && hint->bits == 16) { if (hint && hint->bits == 16) {
// expand 16bit for function // expand 16bit for function

View File

@ -585,6 +585,7 @@ R_API void r_core_anal_cc_init(RCore *core) {
if (!fcn->cc) { if (!fcn->cc) {
fcn->cc = r_anal_cc_default (core->anal); fcn->cc = r_anal_cc_default (core->anal);
} }
fcn->cc = r_str_const (fcn->cc);
} }
sdb_close (sdbs[0]); sdb_close (sdbs[0]);
sdb_free (sdbs[0]); sdb_free (sdbs[0]);

View File

@ -1517,7 +1517,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
eprintf ("Unknown calling convention '%s'\n" eprintf ("Unknown calling convention '%s'\n"
"See afCl for available types\n", cc); "See afCl for available types\n", cc);
} else { } else {
fcn->cc = r_anal_cc_to_constant (core->anal, cc); fcn->cc = r_str_const (r_anal_cc_to_constant (core->anal, cc));
} }
}break; }break;
case 0: case 0:

View File

@ -188,9 +188,14 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
#endif #endif
ptr2 = NULL; ptr2 = NULL;
// remove "dword" 2 // remove "dword" 2
while ((ptr = findNextNumber (ptr))) { char *nptr;
while ((nptr = findNextNumber (ptr))) {
char *optr = ptr;
ptr = nptr;
if (x86) { if (x86) {
for (ptr2 = ptr; *ptr2 && !isx86separator (*ptr2); ptr2++); for (ptr2 = ptr; *ptr2 && !isx86separator (*ptr2); ptr2++) {
// eprintf ("(%s) (%c)\n", optr, *ptr2);
}
} else { } else {
for (ptr2 = ptr; *ptr2 && (*ptr2 != ']' && (*ptr2 != '\x1b') && !ISSEPARATOR (*ptr2)); ptr2++); for (ptr2 = ptr; *ptr2 && (*ptr2 != ']' && (*ptr2 != '\x1b') && !ISSEPARATOR (*ptr2)); ptr2++);
} }

View File

@ -322,7 +322,7 @@ R_API ut64 r_str_hash64(const char *s) {
} }
// Compute a 32bit DJB hash of a string. // Compute a 32bit DJB hash of a string.
R_API ut32 r_str_hash (const char *s) { R_API ut32 r_str_hash(const char *s) {
return (ut32) r_str_hash64 (s); return (ut32) r_str_hash64 (s);
} }
@ -388,7 +388,7 @@ R_API int r_str_word_set0(char *str) {
continue; continue;
} }
if (*p == ' ') { if (*p == ' ') {
char *q = p-1; char *q = p - 1;
if (p > str && (*q == '\\' || !*q)) { if (p > str && (*q == '\\' || !*q)) {
memmove (p, p + 1, strlen (p + 1) + 1); memmove (p, p + 1, strlen (p + 1) + 1);
if (*q == '\\') { if (*q == '\\') {
@ -450,7 +450,7 @@ R_API int r_str_word_set0_stack(char *str) {
continue; continue;
case ')': case ')':
case '}': case '}':
case ']': case ']':
pop = r_stack_pop (s); pop = r_stack_pop (s);
if (pop) { if (pop) {
if ((*(char *)pop == '(' && *p == ')') || if ((*(char *)pop == '(' && *p == ')') ||
@ -485,7 +485,9 @@ R_API char *r_str_word_get0set(char *stra, int stralen, int idx, const char *new
char *p = NULL; char *p = NULL;
char *out; char *out;
int alen, blen, nlen; int alen, blen, nlen;
if (!stra && !newstr) return NULL; if (!stra && !newstr) {
return NULL;
}
if (stra) { if (stra) {
p = (char *)r_str_word_get0 (stra, idx); p = (char *)r_str_word_get0 (stra, idx);
} }
@ -502,7 +504,7 @@ R_API char *r_str_word_get0set(char *stra, int stralen, int idx, const char *new
} }
return out; return out;
} }
alen = (size_t)(p-stra); alen = (size_t)(p - stra);
blen = stralen - ((alen + strlen (p)) + 1); blen = stralen - ((alen + strlen (p)) + 1);
if (blen < 0) { if (blen < 0) {
blen = 0; blen = 0;