| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
import time |
| 24 |
|
| 25 |
from rsyncfns import ( |
| 26 |
SCRATCHDIR, claim_ports, require_tcp, start_rsyncd, test_fail, |
| 27 |
) |
| 28 |
import rsync_proto as rp |
| 29 |
|
| 30 |
PORT = 12957 |
| 31 |
CLEARED_NDX = 1 |
| 32 |
require_tcp("the pure-Python sender needs a real TCP daemon; run with --use-tcp") |
| 33 |
claim_ports(PORT) |
| 34 |
|
| 35 |
mod = SCRATCHDIR / 'cn-mod' |
| 36 |
mod.mkdir(parents=True, exist_ok=True) |
| 37 |
conf = SCRATCHDIR / 'cn.conf' |
| 38 |
log = SCRATCHDIR / 'cn.log' |
| 39 |
conf.write_text(f"""\ |
| 40 |
pid file = {SCRATCHDIR}/cn-rsyncd.pid |
| 41 |
use chroot = no |
| 42 |
log file = {log} |
| 43 |
|
| 44 |
[mod] |
| 45 |
path = {mod} |
| 46 |
read only = no |
| 47 |
""") |
| 48 |
start_rsyncd(conf, PORT) |
| 49 |
|
| 50 |
before = log.read_text(errors='replace') if log.exists() else '' |
| 51 |
s = rp.DaemonSender('127.0.0.1', PORT) |
| 52 |
s.handshake('mod', ['--server', '-e.LsfxCIu', '.', 'mod/'], greeting_version=30) |
| 53 |
|
| 54 |
dup = rp.FileEntry('dup.txt', mode=rp.S_IFREG | 0o644, length=0) |
| 55 |
s.send_flat_flist([dup, dup]) |
| 56 |
|
| 57 |
s.send_transfer_ndx(CLEARED_NDX, iflags=0) |
| 58 |
s.drain(timeout=2.0) |
| 59 |
s.close() |
| 60 |
|
| 61 |
refused = False |
| 62 |
for _ in range(50): |
| 63 |
new = log.read_text(errors='replace')[len(before):] |
| 64 |
if 'refusing transfer of cleared file index' in new: |
| 65 |
refused = True |
| 66 |
break |
| 67 |
time.sleep(0.1) |
| 68 |
|
| 69 |
if not refused: |
| 70 |
new = log.read_text(errors='replace')[len(before):] |
| 71 |
test_fail( |
| 72 |
"receiver did not refuse a transfer ndx targeting a cleared (dup) " |
| 73 |
"file-list entry -- it dereferenced the NULL f_name() and crashed.\n" |
| 74 |
f"daemon log:\n{new}") |
| 75 |
|
| 76 |
print("proto-cleared-ndx: receiver refused a transfer ndx for a cleared " |
| 77 |
"file-list slot (no NULL-deref crash).") |