Debian Codegraph @

testsuite/connect-prog-host-quoting_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 import os
3 import subprocess
4
5 from rsyncfns import SCRATCHDIR, rmtree, rsync_argv, test_fail, test_skipped
6
7 base = SCRATCHDIR / 'connect-prog-quote'
8 rmtree(base)
9 base.mkdir(parents=True)
10 sentinel = base / 'pwned'
11 host = f"localhost;touch${{IFS}}{sentinel};#"
12 env = os.environ.copy()
13 env['RSYNC_CONNECT_PROG'] = 'printf %H >/dev/null'
14
15 proc = subprocess.run(
16 rsync_argv(f'rsync://{host}/mod/', str(base / 'out')),
17 stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=env)
18 out = (proc.stdout or '') + (proc.stderr or '')
19
20 if 'socketpair_tcp failed' in out:
21 test_skipped("RSYNC_CONNECT_PROG socketpair is blocked in this environment")
22 if sentinel.exists():
23 test_fail("RSYNC_CONNECT_PROG %H substitution executed shell syntax from the host")
24 if proc.returncode == 0:
25 test_fail("malicious connect-program probe unexpectedly completed a transfer")
26
27 print("connect-prog-host-quoting: %H host shell syntax is quoted")