Debian Codegraph @

testsuite/safe-arg-leak_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Regression test for KI-54: safe_arg() in filename mode (opt==NULL) must not leak
3 # an uninitialized heap byte. The escape counter and the writer disagreed on a
4 # backslash before a wildcard / a trailing backslash (the strchr(WILD_CHARS,'\0')
5 # NUL footgun), leaving a gap that strlen() walked into. The t_safe_arg helper
6 # links the real options.o, poisons the heap, and checks the quoting is exact.
7
8 import subprocess
9
10 from rsyncfns import TOOLDIR, test_fail, test_skipped
11
12 helper = TOOLDIR / 't_safe_arg'
13 if not helper.is_file():
14 test_skipped("t_safe_arg helper not built")
15
16 proc = subprocess.run([str(helper)], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
17 timeout=30)
18 if proc.returncode != 0:
19 test_fail("safe_arg leaks an uninitialized byte (counter/writer miscount)\n"
20 + (proc.stdout or b'').decode('utf-8', 'replace')
21 + (proc.stderr or b'').decode('utf-8', 'replace'))
22 print((proc.stdout or b'').decode('utf-8', 'replace').strip())