summaryrefslogtreecommitdiffhomepage
path: root/tests/zos/security.sh
blob: 1fa72a9427134b9cf15897e45d7ac653f0c6c37c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Security-relevant behaviour of the shell itself.
#
# Nothing here is z/OS-only, so the expectations are the same as on
# Linux: what the group checks is that the shell never creates a file
# more permissive than the umask allows, never searches the current
# directory for a command, and never re-parses what an expansion or a
# file name produced.  Run on z/OS by make zos-check.
d=sec.tmp
rm -rf "$d"
mkdir "$d" || exit 1

# 1. A file made by redirection takes the umask, not 0666.
(umask 077; : >"$d/close")
echo "umask 077: $(ls -ld "$d/close" | cut -c1-10)"
(umask 022; : >"$d/open")
echo "umask 022: $(ls -ld "$d/open" | cut -c1-10)"

# 2. mkdir likewise.
(umask 022; mkdir "$d/dir")
echo "mkdir 022: $(ls -ld "$d/dir" | cut -c1-10)"

# 3. A redirection that cannot be made fails the command.
if ( : >"$d/nosuchdir/file" ) 2>/dev/null; then
    echo "missing directory: opened"
else
    echo "missing directory: refused"
fi

# 4. The current directory is not searched for a command.  PATH is set
# here because z/OS profiles often end it with a colon, which means "the
# current directory" and would make this pass for the wrong reason.
printf '#!/bin/sh\necho RUN\n' >"$d/runme"
chmod 755 "$d/runme"
(cd "$d" && PATH=/bin:/usr/bin runme) >/dev/null 2>&1
echo "cwd not in PATH: status $?"

# 5. ENV is not read by a non-interactive shell (an interactive one does
# read it, which tests/linux/i-startup.sh covers).
echo 'echo ENV-READ' >"$d/rc"
ENV="$d/rc" PWD=$PWD "$TSH" -c 'echo quiet' 

# 6. A file name is data: the glob expands it and nothing in it runs.
(cd "$d" && : >'a;echo injected' && for f in a\;; do echo "name:$f"; done)

# 7. An expansion's result is not re-parsed.
x='$(echo no)'
echo "$x"

rm -rf "$d"