condition: rework condvar name check

Use memchr() instead of a for loop to detect '/' in the condvar name.
Also unconditionally disallow names starting with a dot.
This commit is contained in:
Jan Engelhardt
2008-04-02 05:00:33 +02:00
parent 586353342f
commit c9579115c3
2 changed files with 9 additions and 18 deletions

View File

@@ -31,8 +31,8 @@ static int condition_parse(int c, char **argv, int invert, unsigned int *flags,
check_inverse(optarg, &invert, &optind, 0); check_inverse(optarg, &invert, &optind, 0);
if (strlen(argv[optind - 1]) < CONDITION_NAME_LEN) if (strlen(optarg) < sizeof(info->name))
strcpy(info->name, argv[optind - 1]); strcpy(info->name, optarg);
else else
exit_error(PARAMETER_PROBLEM, exit_error(PARAMETER_PROBLEM,
"File name too long"); "File name too long");

View File

@@ -136,27 +136,18 @@ condition_mt_check(const char *tablename, const void *entry,
const struct xt_match *match, void *matchinfo, const struct xt_match *match, void *matchinfo,
unsigned int hook_mask) unsigned int hook_mask)
{ {
static const char * const forbidden_names[]={ "", ".", ".." };
const struct xt_condition_mtinfo *info = matchinfo; const struct xt_condition_mtinfo *info = matchinfo;
struct list_head *pos; struct list_head *pos;
struct condition_variable *var, *newvar; struct condition_variable *var, *newvar;
int i; /* Forbid certain names */
if (*info->name == '\0' || *info->name == '.' ||
/* We don't want a '/' in a proc file name. */ info->name[sizeof(info->name)-1] != '\0' ||
for (i=0; i < CONDITION_NAME_LEN && info->name[i] != '\0'; i++) memchr(info->name, '/', sizeof(info->name)) != NULL) {
if (info->name[i] == '/') printk(KERN_INFO KBUILD_MODNAME ": name not allowed or too "
return false; "long: \"%.*s\"\n", sizeof(info->name), info->name);
/* We can't handle file names longer than CONDITION_NAME_LEN and */
/* we want a NULL terminated string. */
if (i == CONDITION_NAME_LEN)
return false; return false;
}
/* We don't want certain reserved names. */
for (i=0; i < sizeof(forbidden_names)/sizeof(char *); i++)
if(strcmp(info->name, forbidden_names[i])==0)
return false;
/* Let's acquire the lock, check for the condition and add it */ /* Let's acquire the lock, check for the condition and add it */
/* or increase the reference counter. */ /* or increase the reference counter. */