| 1 |
|
| 2 |
"""KI-25: send_one_list leaks the id-0 (root) name string. |
| 3 |
|
| 4 |
uidlist.c:send_one_list, when xmit_id0_names is negotiated, passes |
| 5 |
uid_to_user(0)/gid_to_group(0) straight to send_one_name(); those return a |
| 6 |
strdup'd name (uidlist.c:120/137) whose pointer is never stored or freed. Up |
| 7 |
to two small strings leak per transfer. |
| 8 |
|
| 9 |
ASan/LSan reproducer: run an owner/group-preserving transfer (which sends the |
| 10 |
uid+gid lists with the id-0 name) and assert no leak report names send_one_list. |
| 11 |
Gated on an AddressSanitizer build. |
| 12 |
""" |
| 13 |
|
| 14 |
import glob |
| 15 |
import os |
| 16 |
import subprocess |
| 17 |
|
| 18 |
from rsyncfns import ( |
| 19 |
FROMDIR, SCRATCHDIR, RSYNC, |
| 20 |
require_asan, rmtree, rsync_argv, test_fail, |
| 21 |
) |
| 22 |
|
| 23 |
require_asan("KI-25 id-0 name leak is only observable under AddressSanitizer/LSan", RSYNC) |
| 24 |
|
| 25 |
src = FROMDIR |
| 26 |
rmtree(src) |
| 27 |
src.mkdir(parents=True) |
| 28 |
(src / 'f.txt').write_text("hello\n") |
| 29 |
|
| 30 |
asan_log = SCRATCHDIR / 'id0-leak-asan' |
| 31 |
for stale in glob.glob(f"{asan_log}.*"): |
| 32 |
os.unlink(stale) |
| 33 |
os.environ['ASAN_OPTIONS'] = ( |
| 34 |
f"detect_leaks=1:abort_on_error=0:log_path={asan_log}" |
| 35 |
) |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
p = subprocess.run(rsync_argv('-og', '--list-only', f'{src}/'), |
| 42 |
capture_output=True, text=True) |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
if 'f.txt' not in p.stdout: |
| 48 |
test_fail(f"--list-only did not list the source file; leak path not exercised:\n{p.stdout}{p.stderr}") |
| 49 |
|
| 50 |
reports = ''.join(open(r, errors='replace').read() |
| 51 |
for r in glob.glob(f"{asan_log}.*")) |
| 52 |
if 'send_one_list' in reports: |
| 53 |
test_fail("send_one_list leaked the id-0 name string (KI-25):\n" |
| 54 |
+ reports[:1500]) |
| 55 |
|
| 56 |
print("uidlist-id0-name-leak: send_one_list does not leak the id-0 name") |