Enhance error diagnostics about invalid syscalls in fault injection syntax

Validate syscall set before the whole fault injection syntax.

* filter_qualify.c (parse_inject_expression): Add const qualifier to
return type.  Return an empty string when no syscall set is specified.
(qualify_inject_common): Add const qualifier to "name".  Move
qualify_syscall_tokens invocation right after parse_inject_expression.
* tests/qual_fault-syntax.test: Update expected output.
* tests/qual_inject-syntax.test: Likewise.
This commit is contained in:
Дмитрий Левин 2018-01-16 04:34:25 +00:00
parent e6d3c79d60
commit 69bd90eb80
3 changed files with 34 additions and 26 deletions

View File

@ -150,19 +150,20 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts,
return true;
}
static char *
static const char *
parse_inject_expression(char *const str,
struct inject_opts *const fopts,
const bool fault_tokens_only)
{
char *saveptr = NULL;
char *name = NULL;
if (str[0] == '\0' || str[0] == ':')
return "";
for (char *token = strtok_r(str, ":", &saveptr);
token; token = strtok_r(NULL, ":", &saveptr)) {
if (!name)
name = token;
else if (!parse_inject_token(token, fopts, fault_tokens_only))
char *saveptr = NULL;
const char *name = strtok_r(str, ":", &saveptr);
char *token;
while ((token = strtok_r(NULL, ":", &saveptr))) {
if (!parse_inject_token(token, fopts, fault_tokens_only))
return NULL;
}
@ -235,10 +236,17 @@ qualify_inject_common(const char *const str,
.step = 1
};
char *copy = xstrdup(str);
char *name = parse_inject_expression(copy, &opts, fault_tokens_only);
const char *name =
parse_inject_expression(copy, &opts, fault_tokens_only);
if (!name)
error_msg_and_die("invalid %s '%s'", description, str);
struct number_set *tmp_set =
alloc_number_set_array(SUPPORTED_PERSONALITIES);
qualify_syscall_tokens(name, tmp_set);
free(copy);
/* If neither of retval, error, or signal is specified, then ... */
if (!opts.data.flags) {
if (fault_tokens_only) {
@ -251,12 +259,6 @@ qualify_inject_common(const char *const str,
}
}
struct number_set *tmp_set =
alloc_number_set_array(SUPPORTED_PERSONALITIES);
qualify_syscall_tokens(name, tmp_set);
free(copy);
/*
* Initialize inject_vec according to tmp_set.
* Merge tmp_set into inject_set.

View File

@ -40,7 +40,7 @@ fail_with()
"strace -e fault=$* failed to handle an argument error properly"
}
for arg in , ,, ,,, \! \!, \!: \
for arg in '' : :: ::: , ,, ,,, \! \!, \!: \
invalid_syscall_name \
invalid_syscall_name:when=3 \
-1 \!-1 \
@ -62,7 +62,7 @@ for arg in , ,, ,,, \! \!, \!: \
fail_with "$arg"
done
for arg in '' : :: ::: chdir:42 \!chdir:42 \
for arg in chdir:42 \!chdir:42 \
chdir:42:when=7 \
chdir:invalid \
chdir:invalid:when=8 \

View File

@ -40,7 +40,7 @@ fail_with()
"strace -e inject=$* failed to handle an argument error properly"
}
for arg in '' , ,, ,,, : :: ::: \! \!, \!: \
for arg in '' : :: ::: , ,, ,,, \! \!, \!: \
invalid_syscall_name \
invalid_syscall_name:when=3 \
-1 \!-1 \
@ -49,8 +49,20 @@ for arg in '' , ,, ,,, : :: ::: \! \!, \!: \
-2:when=5 \
32767 \!32767 \
32767:when=6 \
42 \
chdir \
file,nonsense \
\!desc,nonsense \
chdir,nonsense \
\!chdir,nonsense \
1,nonsense \
\!1,nonsense \
; do
$STRACE -e inject="$arg" true 2> "$LOG" &&
fail_with "$arg"
LC_ALL=C grep -F "invalid system call '" < "$LOG" > /dev/null ||
fail_with "$arg"
done
for arg in 42 chdir \
chdir:42 \!chdir:42 \
chdir:42:when=7 \
chdir:invalid \
@ -94,12 +106,6 @@ for arg in '' , ,, ,,, : :: ::: \! \!, \!: \
chdir:when=65536:error=30 \
chdir:when=1+65536 \
chdir:when=1+65536:error=31 \
file,nonsense \
\!desc,nonsense \
chdir,nonsense \
\!chdir,nonsense \
1,nonsense \
\!1,nonsense \
chdir:retval=-1 \
chdir:signal=0 \
chdir:signal=129 \