From: Dmitry V. Levin Date: Mon, 15 Jan 2018 18:16:31 +0000 (+0000) Subject: Enhance error diagnostics about invalid syscalls in fault injection syntax X-Git-Tag: v4.21~147 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24d48dde06839ecf848f27e38f4a502e6c44e732;p=strace Enhance error diagnostics about invalid syscalls in fault injection syntax * basic_filters.c (qualify_syscall_tokens): Remove "name" argument, assume its value is "system call". * filter.h (qualify_syscall_tokens): Remove "name" argument. All callers updated. * tests/qual_fault-syntax.test: Update expected output. --- diff --git a/basic_filters.c b/basic_filters.c index 33cf3df0..d20b8809 100644 --- a/basic_filters.c +++ b/basic_filters.c @@ -197,8 +197,7 @@ qualify_syscall(const char *token, struct number_set *set) * according to STR specification. */ void -qualify_syscall_tokens(const char *const str, struct number_set *const set, - const char *const name) +qualify_syscall_tokens(const char *const str, struct number_set *const set) { /* Clear all sets. */ clear_number_set_array(set, SUPPORTED_PERSONALITIES); @@ -242,13 +241,13 @@ qualify_syscall_tokens(const char *const str, struct number_set *const set, token = strtok_r(NULL, ",", &saveptr)) { done = qualify_syscall(token, set); if (!done) - error_msg_and_die("invalid %s '%s'", name, token); + error_msg_and_die("invalid system call '%s'", token); } free(copy); if (!done) - error_msg_and_die("invalid %s '%s'", name, str); + error_msg_and_die("invalid system call '%s'", str); } /* diff --git a/filter.h b/filter.h index fab18127..30c2defb 100644 --- a/filter.h +++ b/filter.h @@ -34,7 +34,6 @@ typedef int (*string_to_uint_func)(const char *); void qualify_tokens(const char *str, struct number_set *set, string_to_uint_func func, const char *name); -void qualify_syscall_tokens(const char *str, struct number_set *set, - const char *name); +void qualify_syscall_tokens(const char *str, struct number_set *set); #endif /* !STRACE_FILTER_H */ diff --git a/filter_qualify.c b/filter_qualify.c index 362857fb..ddba3d5e 100644 --- a/filter_qualify.c +++ b/filter_qualify.c @@ -203,7 +203,7 @@ qualify_trace(const char *const str) { if (!trace_set) trace_set = alloc_number_set_array(SUPPORTED_PERSONALITIES); - qualify_syscall_tokens(str, trace_set, "system call"); + qualify_syscall_tokens(str, trace_set); } static void @@ -211,7 +211,7 @@ qualify_abbrev(const char *const str) { if (!abbrev_set) abbrev_set = alloc_number_set_array(SUPPORTED_PERSONALITIES); - qualify_syscall_tokens(str, abbrev_set, "system call"); + qualify_syscall_tokens(str, abbrev_set); } static void @@ -219,7 +219,7 @@ qualify_verbose(const char *const str) { if (!verbose_set) verbose_set = alloc_number_set_array(SUPPORTED_PERSONALITIES); - qualify_syscall_tokens(str, verbose_set, "system call"); + qualify_syscall_tokens(str, verbose_set); } static void @@ -227,7 +227,7 @@ qualify_raw(const char *const str) { if (!raw_set) raw_set = alloc_number_set_array(SUPPORTED_PERSONALITIES); - qualify_syscall_tokens(str, raw_set, "system call"); + qualify_syscall_tokens(str, raw_set); } static void @@ -258,7 +258,7 @@ qualify_inject_common(const char *const str, struct number_set *tmp_set = alloc_number_set_array(SUPPORTED_PERSONALITIES); - qualify_syscall_tokens(name, tmp_set, description); + qualify_syscall_tokens(name, tmp_set); free(copy); diff --git a/tests/qual_fault-syntax.test b/tests/qual_fault-syntax.test index 0cce539a..46e108b6 100755 --- a/tests/qual_fault-syntax.test +++ b/tests/qual_fault-syntax.test @@ -2,7 +2,7 @@ # # Check -e fault= syntax. # -# Copyright (c) 2016-2017 Dmitry V. Levin +# Copyright (c) 2016-2018 Dmitry V. Levin # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -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 \ @@ -49,7 +49,20 @@ for arg in '' , ,, ,,, : :: ::: \! \!, \!: \ -2:when=5 \ 32767 \!32767 \ 32767:when=6 \ - chdir:42 \!chdir:42 \ + file,nonsense \ + \!desc,nonsense \ + chdir,nonsense \ + \!chdir,nonsense \ + 1,nonsense \ + \!1,nonsense \ + ; do + $STRACE -e fault="$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 '' : :: ::: chdir:42 \!chdir:42 \ chdir:42:when=7 \ chdir:invalid \ chdir:invalid:when=8 \ @@ -92,12 +105,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=0 \ chdir:signal=1 \ chdir:error=1:error=2 \