#!/bin/sh

set -e

. "${srcdir:-.}/common.sh"

get_common_syscalls >"$TMP"/tmpl
cat >>"$TMP"/tmpl <<EOF
# what we are testing
EOF

for i in 'bar' '-1' '0 - -1 0' '--10' '0:10' '1-10' '0,1' '0x0' 'a1' '1a' '1-' '1\\n1' '1\ 2' '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999' ; do
    printf "Test bad seccomp arg filtering (setpriority %s)" "$i"
    cat "$TMP"/tmpl >"$TMP"/snap.name.app
    echo "setpriority $i" >>"$TMP"/snap.name.app

    if $L snap.name.app /bin/true 2>/dev/null; then
        # true returned successfully, bad arg test failed
        cat "$TMP"/snap.name.app
        FAIL
    fi

    # all good
    PASS
done

# > SC_ARGS_MAXLENGTH in seccomp.c
for i in '- - - - - - 7' '1 2 3 4 5 6 7' ; do
    printf "Test bad seccomp arg filtering (too many args (> 6): %s)" "$i"
    cat "$TMP"/tmpl >"$TMP"/snap.name.app
    echo "mbind $i" >>"$TMP"/snap.name.app

    if $L snap.name.app /bin/true 2>/dev/null; then
        # true returned successfully, bad arg test failed
        FAIL
    else
        PASS
    fi
done
