Debian Codegraph @

testsuite/clean-fname-underflow_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/clean-fname-underflow.test.
3 #
4 # Ensure clean_fname() does not read-before-buffer when collapsing "..".
5 # Exercises the --server path where a crafted merge filename hits
6 # clean_fname(); the test fails if rsync dies from a signal (status >= 128)
7 # AND if rsync exits 0 -- the bogus input must be rejected (clean_fname
8 # collapses "a/../test" to "test", whose merge file does not exist, so rsync
9 # errors out non-zero). Accepting it would mean the name was mis-collapsed.
10
11 import os
12 import shlex
13 import subprocess
14
15 from rsyncfns import RSYNC, TMPDIR, test_fail, split_rsync_cmd
16
17
18 workdir = TMPDIR / 'workdir'
19 (workdir / 'mod').mkdir(parents=True, exist_ok=True)
20 os.chdir(workdir)
21
22 # RSYNC may be a multi-word command (e.g. valgrind + rsync); take just the
23 # binary path, matching the shell test's `echo $RSYNC | sed 's/ .*//'`.
24 rsync_bin = split_rsync_cmd(RSYNC)[0]
25
26 proc = subprocess.run(
27 [rsync_bin, '--server', '--sender', '-vlr',
28 '--filter=merge a/../test', '.', 'mod/'],
29 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
30 )
31
32 if proc.returncode >= 128:
33 test_fail(f"rsync exited due to a signal (status={proc.returncode})")
34 if proc.returncode == 0:
35 test_fail("rsync accepted the bogus 'a/../test' merge filter (expected a "
36 "non-zero rejection); clean_fname() may have mis-collapsed it")
37
38 print("OK: clean_fname() handled 'a/../test' without crashing, and rejected it")