| 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 |
import glob |
| 31 |
import os |
| 32 |
|
| 33 |
from rsyncfns import ( |
| 34 |
SCRATCHDIR, claim_ports, require_asan, require_tcp, start_rsyncd, test_fail, |
| 35 |
) |
| 36 |
import rsync_proto as rp |
| 37 |
|
| 38 |
PORT = 12953 |
| 39 |
require_tcp("the pure-Python sender needs a real TCP daemon; run with --use-tcp") |
| 40 |
require_asan("the FLAG_HLINKED pool underflow is only observable under " |
| 41 |
"AddressSanitizer + the lib/pool_alloc.c redzone") |
| 42 |
claim_ports(PORT) |
| 43 |
|
| 44 |
mod = SCRATCHDIR / 'hlink-oob-mod' |
| 45 |
mod.mkdir(parents=True, exist_ok=True) |
| 46 |
conf = SCRATCHDIR / 'hlink-oob.conf' |
| 47 |
conf.write_text(f"""\ |
| 48 |
pid file = {SCRATCHDIR}/hlink-oob-rsyncd.pid |
| 49 |
use chroot = no |
| 50 |
|
| 51 |
[mod] |
| 52 |
path = {mod} |
| 53 |
read only = no |
| 54 |
""") |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
asan_log = SCRATCHDIR / 'hlink-oob-asan' |
| 59 |
for stale in glob.glob(f"{asan_log}.*"): |
| 60 |
os.unlink(stale) |
| 61 |
prev = os.environ.get('ASAN_OPTIONS', '') |
| 62 |
os.environ['ASAN_OPTIONS'] = ( |
| 63 |
(prev + ':' if prev else '') + f'detect_leaks=0:abort_on_error=1:log_path={asan_log}') |
| 64 |
|
| 65 |
start_rsyncd(conf, PORT) |
| 66 |
|
| 67 |
s = rp.DaemonSender('127.0.0.1', PORT) |
| 68 |
|
| 69 |
|
| 70 |
s.handshake('mod', ['--server', '-re.iLsfxCIu', '--checksum', '.', 'mod/'], |
| 71 |
greeting_version=30) |
| 72 |
evil = rp.FileEntry('h.txt', mode=rp.S_IFREG | 0o644, length=0, |
| 73 |
extra_flags=rp.XMIT_HLINKED | rp.XMIT_HLINK_FIRST, |
| 74 |
csum=b'\x41' * 64) |
| 75 |
s.send_flat_flist([evil]) |
| 76 |
s.drain(timeout=3.0) |
| 77 |
s.close() |
| 78 |
|
| 79 |
reports = glob.glob(f"{asan_log}.*") |
| 80 |
text = ''.join(open(r, errors='replace').read() for r in reports) |
| 81 |
if 'AddressSanitizer' in text: |
| 82 |
test_fail( |
| 83 |
"receiver hit an AddressSanitizer error parsing an XMIT_HLINKED entry " |
| 84 |
"sent without -H -- the FLAG_HLINKED pool underflow is unguarded:\n" |
| 85 |
+ text[:1500]) |
| 86 |
|
| 87 |
print("proto-hlink-flag-oob: XMIT_HLINKED-without-H entry parsed with no " |
| 88 |
"pool underflow (FLAG_HLINKED gated on preserve_hard_links).") |