Remove RParse.hint to fix Segfaults ##parse (#13806)

This commit is contained in:
Florian Märkl 2019-04-18 15:09:48 +02:00 committed by GitHub
parent 2325e7f2ff
commit f5dfae611f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 26 deletions

View File

@ -1547,7 +1547,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
// 0x33->sym.xx
char *p = strdup (strsub);
if (p) {
r_parse_filter (core->parser, addr, core->flags, p,
r_parse_filter (core->parser, addr, core->flags, hint, p,
strsub, sizeof (strsub), be);
free (p);
}
@ -6063,8 +6063,10 @@ static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn,
r_parse_varsub (core->parser, fcn, addr, asmop.size,
ba, ba, sizeof (asmop.buf_asm));
}
r_parse_filter (core->parser, addr, core->flags,
RAnalHint *hint = r_anal_hint_get (core->anal, addr);
r_parse_filter (core->parser, addr, core->flags, hint,
ba, str, sizeof (str), core->print->big_endian);
r_anal_hint_free (hint);
r_asm_op_set_asm (&asmop, ba);
free (ba);
if (color && has_color) {
@ -6419,8 +6421,10 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
r_io_read_at (core->io, ref->addr, buf, sizeof (buf));
r_asm_set_pc (core->assembler, ref->addr);
r_asm_disassemble (core->assembler, &asmop, buf, sizeof(buf));
r_parse_filter (core->parser, ref->addr, core->flags, r_asm_op_get_asm (&asmop),
RAnalHint *hint = r_anal_hint_get (core->anal, ref->addr);
r_parse_filter (core->parser, ref->addr, core->flags, hint, r_asm_op_get_asm (&asmop),
str, sizeof (str), core->print->big_endian);
r_anal_hint_free (hint);
if (has_color) {
desc = desc_to_free = r_print_colorize_opcode (core->print, str,
core->cons->context->pal.reg, core->cons->context->pal.num, false, fcn ? fcn->addr : 0);

View File

@ -1864,8 +1864,10 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear
r_asm_set_pc (core->assembler, ref->addr);
r_asm_disassemble (core->assembler, &asmop, buf, size);
fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0);
r_parse_filter (core->parser, ref->addr, core->flags, r_strbuf_get (&asmop.buf_asm),
RAnalHint *hint = r_anal_hint_get (core->anal, ref->addr);
r_parse_filter (core->parser, ref->addr, core->flags, hint, r_strbuf_get (&asmop.buf_asm),
str, sizeof (str), core->print->big_endian);
r_anal_hint_free (hint);
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr);
char *buf_fcn = comment
? r_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", strtok (comment, "\n"))
@ -2223,8 +2225,10 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch
char tmp[128] = {
0
};
r_parse_filter (core->parser, hit->addr, core->flags, hit->code, tmp, sizeof (tmp),
RAnalHint *hint = r_anal_hint_get (core->anal, hit->addr);
r_parse_filter (core->parser, hit->addr, core->flags, hint, hit->code, tmp, sizeof (tmp),
core->print->big_endian);
r_anal_hint_free (hint);
r_cons_printf ("0x%08"PFMT64x " # %i: %s\n",
hit->addr, hit->len, tmp);
} else {

View File

@ -916,7 +916,6 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop));
}
/* initialize */
core->parser->hint = ds->hint;
core->parser->relsub = r_config_get_i (core->config, "asm.relsub");
core->parser->regsub = r_config_get_i (core->config, "asm.regsub");
core->parser->relsub_addr = 0;
@ -989,7 +988,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
core->parser->relsub_addr = killme;
}
}
r_parse_filter (core->parser, ds->vat, core->flags, asm_str,
r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, asm_str,
ds->str, sizeof (ds->str), core->print->big_endian);
core->parser->flagspace = ofs;
free (ds->opstr);
@ -5382,9 +5381,7 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc
core->parser->flagspace = NULL;
}
}
core->parser->hint = ds->hint;
ds->hint = NULL;
r_parse_filter (core->parser, ds->vat, core->flags, r_asm_op_get_asm (&ds->asmop),
r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, r_asm_op_get_asm (&ds->asmop),
ds->str, sizeof (ds->str), core->print->big_endian);
ds->opstr = strdup (ds->str);
asm_str = colorize_asm_string (core, ds, true);
@ -5602,7 +5599,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
if (buf) {
strcpy (buf, aop);
buf = ds_sub_jumps (ds, buf);
r_parse_filter (core->parser, ds->vat, core->flags, buf,
r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, buf,
str, sizeof (str), core->print->big_endian);
r_asm_op_set_asm (&asmop, buf);
free (buf);
@ -5788,7 +5785,7 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
count ++;
switch (mode) {
case 'i':
r_parse_filter (core->parser, ds->vat, core->flags, r_asm_op_get_asm (&asmop),
r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, r_asm_op_get_asm (&asmop),
str, sizeof (str), core->print->big_endian);
if (scr_color) {
RAnalOp aop;
@ -6065,9 +6062,10 @@ toro:
r_parse_immtrim (asm_str);
}
if (filter) {
core->parser->hint = r_anal_hint_get (core->anal, at);
r_parse_filter (core->parser, at, core->flags,
RAnalHint *hint = r_anal_hint_get (core->anal, at);
r_parse_filter (core->parser, at, core->flags, hint,
asm_str, opstr, sizeof (opstr) - 1, core->print->big_endian);
r_anal_hint_free (hint);
asm_str = (char *)&opstr;
}
if (show_color) {

View File

@ -1684,8 +1684,6 @@ R_API void r_anal_merge_hint_ranges(RAnal *a);
R_API void r_anal_hint_del (RAnal *anal, ut64 addr, int size);
R_API void r_anal_hint_clear (RAnal *a);
R_API RAnalHint *r_anal_hint_from_string(RAnal *a, ut64 addr, const char *str);
R_API RAnalHint *r_anal_hint_at (RAnal *a, ut64 from);
R_API RAnalHint *r_anal_hint_add (RAnal *a, ut64 from, int size);
R_API void r_anal_hint_free (RAnalHint *h);
R_API RAnalHint *r_anal_hint_get(RAnal *anal, ut64 addr);
R_API void r_anal_hint_set_syntax (RAnal *a, ut64 addr, const char *syn);

View File

@ -32,7 +32,6 @@ typedef struct r_parse_t {
char *retleave_asm;
struct r_parse_plugin_t *cur;
RAnal *anal; // weak anal ref
RAnalHint *hint; // weak anal ref
RList *parsers;
RAnalVarList varlist;
char* (*get_op_ireg)(void *user, ut64 addr);
@ -61,7 +60,7 @@ R_API int r_parse_list(RParse *p);
R_API int r_parse_use(RParse *p, const char *name);
R_API int r_parse_parse(RParse *p, const char *data, char *str);
R_API int r_parse_assemble(RParse *p, char *data, char *str);
R_API int r_parse_filter(RParse *p, ut64 addr, RFlag *f, char *data, char *str, int len, bool big_endian);
R_API int r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian);
R_API bool r_parse_varsub(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len);
R_API char *r_parse_c_string(RAnal *anal, const char *code, char **error_msg);
R_API char *r_parse_c_file(RAnal *anal, const char *path, char **error_msg);

View File

@ -225,7 +225,7 @@ static void replaceRegisters (RReg *reg, char *s, bool x86) {
}
}
static int filter(RParse *p, ut64 addr, RFlag *f, char *data, char *str, int len, bool big_endian) {
static int filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian) {
char *ptr = data, *ptr2, *ptr_backup;
RAnalFunction *fcn;
RFlagItem *flag;
@ -410,19 +410,19 @@ static int filter(RParse *p, ut64 addr, RFlag *f, char *data, char *str, int len
}
}
}
if (p->hint) {
const int nw = p->hint->nword;
if (hint) {
const int nw = hint->nword;
if (count != nw) {
ptr = ptr2;
continue;
}
int pnumleft, immbase = p->hint->immbase;
int pnumleft, immbase = hint->immbase;
char num[256] = {0}, *pnum, *tmp;
bool is_hex = false;
int tmp_count;
if (p->hint->offset) {
if (hint->offset) {
*ptr = 0;
snprintf (str, len, "%s%s%s", data, p->hint->offset, (ptr != ptr2)? ptr2: "");
snprintf (str, len, "%s%s%s", data, hint->offset, (ptr != ptr2)? ptr2: "");
return true;
}
strncpy (num, ptr, sizeof (num)-2);
@ -591,8 +591,8 @@ R_API char *r_parse_immtrim(char *opstr) {
return opstr;
}
R_API int r_parse_filter(RParse *p, ut64 addr, RFlag *f, char *data, char *str, int len, bool big_endian) {
filter (p, addr, f, data, str, len, big_endian);
R_API int r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian) {
filter (p, addr, f, hint, data, str, len, big_endian);
if (p->cur && p->cur->filter) {
return p->cur->filter (p, addr, f, data, str, len, big_endian);
}