mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-01 00:51:19 +00:00
edbcb1cfce
- Lot of syntax indentation fixes * Use r_name_filter in r_flags - Fix dangerous flagnames issue
67 lines
1.1 KiB
C
67 lines
1.1 KiB
C
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
|
|
|
#include <r_util.h>
|
|
|
|
#define IS_PRINTABLE(x) (x>=' '&&x<='~')
|
|
|
|
static int r_name_validate_char(const char ch) {
|
|
switch (ch) {
|
|
case '*':
|
|
case '/':
|
|
case '+':
|
|
case '|':
|
|
case '&':
|
|
case ';':
|
|
case ':':
|
|
case '>':
|
|
case '<':
|
|
case '"':
|
|
case '#':
|
|
case '%':
|
|
case '(':
|
|
case ')':
|
|
case '`':
|
|
case '\'':
|
|
case '-':
|
|
case ' ':
|
|
case '\n':
|
|
case '\t':
|
|
case '[':
|
|
case ']':
|
|
case '@':
|
|
return 0;
|
|
default:
|
|
if (((ch >= '0') && (ch <= '9')))
|
|
return R_TRUE;
|
|
if (!IS_PRINTABLE (ch))
|
|
return R_FALSE;
|
|
}
|
|
return R_TRUE;
|
|
}
|
|
|
|
R_API int r_name_check(const char *name) {
|
|
if (name[0]=='\0')
|
|
return R_FALSE;
|
|
for (;*name!='\0'; name++)
|
|
if (!r_name_validate_char (*name))
|
|
return R_FALSE;
|
|
return R_TRUE;
|
|
}
|
|
|
|
R_API int r_name_filter(char *name, int maxlen) {
|
|
int i;
|
|
char *oname;
|
|
name = oname = r_str_trim (name);
|
|
for (i=0; *name!='\0'; name++, i++) {
|
|
if (maxlen && i>maxlen) {
|
|
name[0] = '\0';
|
|
break;
|
|
}
|
|
if (!r_name_validate_char (*name)) {
|
|
r_str_ccpy (name, name+1, 0);
|
|
name = name -1;
|
|
}
|
|
}
|
|
return r_name_check (oname);
|
|
}
|