#!/bin/sh

set -e

. "${srcdir:-.}/snap-confine/tests/common.sh"

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

# Test these individually since you can't store \0 in a variable
printf "Test bad seccomp arg filtering (socket S\\\0CK_STREAM)"
cat "$TMP"/tmpl >"$TMP"/snap.name.app
printf "socket S\0CK_STREAM\n" >>"$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
else
    PASS
fi

# an embedded null that is after a valid arg stops processing of the arg
# (limitation of fgets() implementation)
printf "Test ok seccomp arg filtering (socket SOCK_STREAM\\\0bad stuff)"
cat "$TMP"/tmpl >"$TMP"/snap.name.app
printf "socket SOCK_STREAM\0bad stuff\n" >>"$TMP"/snap.name.app

if $L snap.name.app /bin/true 2>/dev/null; then
    PASS
else
    cat "$TMP"/snap.name.app
    FAIL
fi
