1 #!/bin/sh 2 # 3 # Check syscall set parsing syntax. 4 # 5 # Copyright (c) 2016-2018 Dmitry V. Levin <ldv (at] altlinux.org> 6 # Copyright (c) 2017 Nikolay Marchuk <marchuk.nikolay.a (at] gmail.com> 7 # All rights reserved. 8 # 9 # Redistribution and use in source and binary forms, with or without 10 # modification, are permitted provided that the following conditions 11 # are met: 12 # 1. Redistributions of source code must retain the above copyright 13 # notice, this list of conditions and the following disclaimer. 14 # 2. Redistributions in binary form must reproduce the above copyright 15 # notice, this list of conditions and the following disclaimer in the 16 # documentation and/or other materials provided with the distribution. 17 # 3. The name of the author may not be used to endorse or promote products 18 # derived from this software without specific prior written permission. 19 # 20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 . "${srcdir=.}/syntax.sh" 32 33 check_syscall() 34 { 35 [ -z "$2" ] || check_e "invalid system call '$1'" -e"$2" 36 37 check_e "invalid system call '$1'" -e "$2" 38 check_e "invalid system call '$1'" -etrace="$2" 39 check_e "invalid system call '$1'" -e trace="$2" 40 41 check_e "invalid system call '$1'" -eabbrev="$2" 42 check_e "invalid system call '$1'" -e abbrev="$2" 43 44 check_e "invalid system call '$1'" -everbose="$2" 45 check_e "invalid system call '$1'" -e verbose="$2" 46 47 check_e "invalid system call '$1'" -eraw="$2" 48 check_e "invalid system call '$1'" -e raw="$2" 49 50 check_e "invalid system call '$1'" -einject="$2" 51 check_e "invalid system call '$1'" -e inject="$2" 52 check_e "invalid system call '$1'" -einject="$2:" 53 check_e "invalid system call '$1'" -einject="$2::" 54 check_e "invalid system call '$1'" -einject="$2:::" 55 check_e "invalid system call '$1'" -e inject="$2:" 56 check_e "invalid system call '$1'" -e inject="$2::" 57 check_e "invalid system call '$1'" -e inject="$2:::" 58 check_e "invalid system call '$1'" -einject="$2:when=3" 59 check_e "invalid system call '$1'" -e inject="$2:when=3" 60 61 check_e "invalid system call '$1'" -efault="$2" 62 check_e "invalid system call '$1'" -e fault="$2" 63 check_e "invalid system call '$1'" -efault="$2:" 64 check_e "invalid system call '$1'" -efault="$2::" 65 check_e "invalid system call '$1'" -efault="$2:::" 66 check_e "invalid system call '$1'" -e fault="$2:" 67 check_e "invalid system call '$1'" -e fault="$2::" 68 check_e "invalid system call '$1'" -e fault="$2:::" 69 check_e "invalid system call '$1'" -efault="$2:when=4" 70 check_e "invalid system call '$1'" -e fault="$2:when=4" 71 } 72 73 for arg in '' , ,, ,,, ; do 74 check_syscall "$arg" "$arg" 75 check_syscall "!$arg" "!$arg" 76 done 77 78 for arg in -1 -2 -3 -4 -5 \ 79 invalid_syscall_name \ 80 0x 0y \ 81 32767 \ 82 2147483647 \ 83 2147483648 \ 84 4294967295 \ 85 4294967296 \ 86 /non_syscall \ 87 % %not_a_class \ 88 ; do 89 check_syscall "$arg" "$arg" 90 check_syscall "$arg" "!$arg" 91 check_syscall "$arg" "1,$arg" 92 done 93 94 for arg in '!chdir' none all; do 95 check_syscall "$arg" "1,$arg" 96 done 97 98 # invalid syscall, multiple syscalls 99 for arg in %desc \ 100 %file \ 101 %memory \ 102 %process \ 103 %network \ 104 chdir \ 105 1 \ 106 ?32767 \ 107 ?invalid \ 108 ?%not_a_class \ 109 ?/non_syscall \ 110 ; do 111 check_syscall nonsense "$arg,nonsense" 112 check_syscall nonsense "!$arg,nonsense" 113 check_syscall nonsense "nonsense,$arg" 114 check_syscall nonsense "!nonsense,$arg" 115 done 116 117 check_e_using_grep 'regcomp: \+id: [[:alpha:]].+' -e trace='/+id' 118 check_e_using_grep 'regcomp: \*id: [[:alpha:]].+' -e trace='/*id' 119 check_e_using_grep 'regcomp: \{id: [[:alpha:]].+' -e trace='/{id' 120 check_e_using_grep 'regcomp: \(id: [[:alpha:]].+' -e trace='/(id' 121 check_e_using_grep 'regcomp: \[id: [[:alpha:]].+' -e trace='/[id' 122