Skip to content

Commit

Permalink
Fix #20040 - invalid char bug in afl* when function names contain ';'…
Browse files Browse the repository at this point in the history
… ##projects

* Rename r_name_filter2() to r_name_filter_dup()
* Abi break as now `r_name_validate_char` is no longer an static inline
* Fixes some project save/load inconsistencies
  • Loading branch information
trufae authored and pull[bot] committed Jun 9, 2022
1 parent 703286b commit c9e5454
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion libr/anal/fcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ R_API char *r_anal_function_get_signature(RAnalFunction *function) {
free (sdb_arg_i);
}

char *sane = r_name_filter2 (realname);
char *sane = r_name_filter_dup (realname);
if (sane) {
r_str_replace_ch (sane, ':', '_', true);
realname = sane;
Expand Down
2 changes: 1 addition & 1 deletion libr/anal/flirt.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ static int module_match_buffer(RAnal *anal, const RFlirtModule *module, ut8 *b,
if (!flirt_func->name[name_offs]) {
continue;
}
name = r_name_filter2 (flirt_func->name + name_offs);
name = r_name_filter_dup (flirt_func->name + name_offs);
free (next_module_function->name);
next_module_function->name = r_str_newf ("flirt.%s", name);
anal->flb.set (anal->flb.f, next_module_function->name,
Expand Down
8 changes: 4 additions & 4 deletions libr/bin/format/objc/mach0_classes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ ut32 fields_offset;
eprintf (" members: 0x%08"PFMT64x"\n", NCD (NCD_MEMBERS));
eprintf (" fields: 0x%08"PFMT64x"\n", NCD (NCD_NFIELDS));
eprintf (" fieldsat:0x%08"PFMT64x"\n", NCD (NCD_OFIELDS));
char * tn = r_name_filter2 (typename);
char * tn = r_name_filter_dup (typename);
r_cons_printf ("f sym.swift.%s.init = 0x%08"PFMT64x"\n",
tn, bf->o->baddr + NCD (NCD_ACCESSFCNPTR));
free (tn);
Expand All @@ -1295,7 +1295,7 @@ ut32 fields_offset;

static void parse_type(RBinFile *bf, SwiftType st) {
char *otypename = readstr (bf, st.name_addr);
char *typename = r_name_filter2 (otypename);
char *typename = r_name_filter_dup (otypename);
// eprintf ("methods:\n");
if (st.members != UT64_MAX) {
ut8 buf[512];
Expand All @@ -1317,7 +1317,7 @@ static void parse_type(RBinFile *bf, SwiftType st) {
r_list_foreach (symbols, iter, sym) {
if (sym->vaddr == method_addr) {
free (method_name);
method_name = r_name_filter2 (sym->name);
method_name = r_name_filter_dup (sym->name);
break;
}
}
Expand All @@ -1342,7 +1342,7 @@ static void parse_type(RBinFile *bf, SwiftType st) {
if (!field_name) {
break;
}
char *fn = r_name_filter2 (field_name);
char *fn = r_name_filter_dup (field_name);
r_cons_printf ("f sym.swift.%s.field.%s = 0x%08"PFMT64x"\n",
typename, fn, bf->o->baddr + field_method_addr);
free (fn);
Expand Down
2 changes: 1 addition & 1 deletion libr/bin/pdb/pdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ static void print_gvars(RPdb *pdb, ut64 img_base, PJ *pj, int format) {
case 1:
case '*':
case 'r':
filtered_name = r_name_filter2 (r_str_trim_head_ro (name));
filtered_name = r_name_filter_dup (r_str_trim_head_ro (name));
pdb->cb_printf ("f pdb.%s = 0x%" PFMT64x " # %d %.*s\n",
filtered_name,
(ut64) (img_base + omap_remap ((omap) ? (omap->stream) : 0, gdata->offset + sctn_header->virtual_address)),
Expand Down
4 changes: 3 additions & 1 deletion libr/core/canal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3025,7 +3025,9 @@ static int fcn_print_detail(RCore *core, RAnalFunction *fcn) {
if (paren) {
*paren = '\0';
}
r_cons_printf ("\"f %s %"PFMT64u" 0x%08"PFMT64x"\"\n", name, r_anal_function_linear_size (fcn), fcn->addr);
char *fname = r_name_filter_dup (name);
r_cons_printf ("\"f %s %"PFMT64u" 0x%08"PFMT64x"\"\n", fname, r_anal_function_linear_size (fcn), fcn->addr);
free (fname);
r_cons_printf ("\"af+ 0x%08"PFMT64x" %s %c %c\"\n",
fcn->addr, name, //r_anal_function_size (fcn), name,
fcn->type == R_ANAL_FCN_TYPE_LOC?'l':
Expand Down
5 changes: 4 additions & 1 deletion libr/core/cmd_anal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3374,14 +3374,15 @@ static bool __setFunctionName(RCore *core, ut64 addr, const char *_name, bool pr
r_return_val_if_fail (core && _name, false);
_name = r_str_trim_head_ro (_name);
char *name = getFunctionName (core, addr, _name, prefix);
char *fname = r_name_filter_dup (name);
// RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_ANY);
RAnalFunction *fcn = r_anal_get_function_at (core->anal, addr);
if (fcn) {
char *oname = strdup (fcn->name);
RFlagItem *flag = r_flag_get (core->flags, fcn->name);
if (flag && flag->space && strcmp (flag->space->name, R_FLAGS_FS_FUNCTIONS) == 0) {
// Only flags in the functions fs should be renamed, e.g. we don't want to rename symbol flags.
r_flag_rename (core->flags, flag, name);
r_flag_rename (core->flags, flag, fname);
} else {
// No flag or not specific to the function, create a new one.
r_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS);
Expand All @@ -3395,9 +3396,11 @@ static bool __setFunctionName(RCore *core, ut64 addr, const char *_name, bool pr
}
free (oname);
free (name);
free (fname);
return true;
}
free (name);
free (fname);
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions libr/core/cmd_zign.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2021 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2022 - pancake, nibble */

#include <r_core.h>
#include <r_anal.h>
Expand Down Expand Up @@ -428,7 +428,7 @@ static void apply_name(RCore *core, RAnalFunction *fcn, RSignItem *it, bool rad)
r_return_if_fail (core && fcn && it && it->name);
const char *name = it->realname? it->realname: it->name;
if (rad) {
char *tmp = r_name_filter2 (name);
char *tmp = r_name_filter_dup (name);
if (tmp) {
r_cons_printf ("\"afn %s @ 0x%08" PFMT64x "\"\n", tmp, fcn->addr);
free (tmp);
Expand All @@ -450,7 +450,7 @@ static void apply_flag(RCore *core, RSignItem *it, ut64 addr, int size, int coun
char *name = r_str_newf ("%s.%s.%s_%d", zign_prefix, prefix, it->name, count);
if (name) {
if (rad) {
char *tmp = r_name_filter2 (name);
char *tmp = r_name_filter_dup (name);
if (tmp) {
r_cons_printf ("f %s %d @ 0x%08" PFMT64x "\n", tmp, size, addr);
free (tmp);
Expand Down
4 changes: 1 addition & 3 deletions libr/flag/flag.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2021 - pancake, ret2libc */
/* radare - LGPL - Copyright 2007-2022 - pancake, ret2libc */

#include <r_flag.h>
#include <r_util.h>
Expand Down Expand Up @@ -399,11 +399,9 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) {
rad = pfx[0];
pfx = NULL;
}

if (pfx && !*pfx) {
pfx = NULL;
}

switch (rad) {
case 'q':
r_flag_foreach_space (f, r_flag_space_cur (f), print_flag_name, f);
Expand Down
11 changes: 2 additions & 9 deletions libr/include/r_util/r_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ extern "C" {
#endif

R_API bool r_name_validate_print(const char ch);
// R_API bool r_name_validate_char(const char ch);
R_API bool r_name_validate_char(const char ch);
R_API bool r_name_validate_first(const char ch);
R_API bool r_name_check(const char *s);
R_API const char *r_name_filter_ro(const char *a);
R_API bool r_name_filter_flag(char *s);
R_API bool r_name_filter_print(char *s);
R_API bool r_name_filter(char *name, int maxlen);
R_API char *r_name_filter2(const char *name);

static inline bool r_name_validate_char(const char ch) {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || IS_DIGIT (ch)) {
return true;
}
return (ch == '.' || ch == ':' || ch == '_');
}
R_API char *r_name_filter_dup(const char *name);

#ifdef __cplusplus
}
Expand Down
15 changes: 4 additions & 11 deletions libr/util/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,13 @@ R_API bool r_name_validate_dash(const char ch) {
return false;
}

#if 0
R_API bool r_name_validate_char(const char ch) {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || IS_DIGIT (ch)) {
return true;
}
switch (ch) {
case '.':
case ':':
case '_':
return true;
}
return false;
return (ch == '.' || ch == ':' || ch == '_');
// return (ch == ';' || ch == '.' || ch == ':' || ch == '_');
}
#endif

R_API bool r_name_validate_first(const char ch) {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
Expand All @@ -106,7 +99,7 @@ R_API bool r_name_check(const char *s) {
}

static inline bool is_special_char(char n) {
return (n == 'b' || n == 'f' || n == 'n' || n == 'r' || n == 't' || n == 'v' || n == 'a');
return (n == 's' || n == 'b' || n == 'f' || n == 'n' || n == 'r' || n == 't' || n == 'v' || n == 'a');
}

R_API const char *r_name_filter_ro(const char *a) {
Expand Down Expand Up @@ -197,7 +190,7 @@ R_API bool r_name_filter(char *s, int maxlen) {
#endif
}

R_API char *r_name_filter2(const char *name) {
R_API char *r_name_filter_dup(const char *name) {
char *s = strdup (name);
r_name_filter (s, -1);
return s;
Expand Down
4 changes: 4 additions & 0 deletions libr/util/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,10 @@ R_API int r_str_unescape(char *buf) {
case 'e':
buf[i] = 0x1b;
break;
case ' ':
case 's':
buf[i] = ' ';
break;
case '\\':
buf[i] = '\\';
break;
Expand Down

0 comments on commit c9e5454

Please sign in to comment.