| 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 |
import time |
| 27 |
|
| 28 |
from rsyncfns import ( |
| 29 |
SCRATCHDIR, claim_ports, require_tcp, start_rsyncd, test_fail, |
| 30 |
) |
| 31 |
import rsync_proto as rp |
| 32 |
|
| 33 |
PORT = 12959 |
| 34 |
CLEARED_NDX = 1 |
| 35 |
require_tcp("the pure-Python sender needs a real TCP daemon; run with --use-tcp") |
| 36 |
claim_ports(PORT) |
| 37 |
|
| 38 |
mod = SCRATCHDIR / 'cd-mod' |
| 39 |
mod.mkdir(parents=True, exist_ok=True) |
| 40 |
conf = SCRATCHDIR / 'cd.conf' |
| 41 |
log = SCRATCHDIR / 'cd.log' |
| 42 |
conf.write_text(f"""\ |
| 43 |
pid file = {SCRATCHDIR}/cd-rsyncd.pid |
| 44 |
use chroot = no |
| 45 |
log file = {log} |
| 46 |
|
| 47 |
[mod] |
| 48 |
path = {mod} |
| 49 |
read only = no |
| 50 |
""") |
| 51 |
start_rsyncd(conf, PORT) |
| 52 |
|
| 53 |
before = log.read_text(errors='replace') if log.exists() else '' |
| 54 |
s = rp.DaemonSender('127.0.0.1', PORT) |
| 55 |
s.handshake('mod', ['--server', '-re.iLsfxCIu', '.', 'mod/'], greeting_version=30) |
| 56 |
|
| 57 |
|
| 58 |
d = rp.FileEntry('d', mode=rp.S_IFDIR | 0o755, length=0, extra_flags=rp.XMIT_TOP_DIR) |
| 59 |
f = rp.FileEntry('f', mode=rp.S_IFREG | 0o644, length=100) |
| 60 |
s.send_data(d.encode() + d.encode() + f.encode() + rp.end_of_flist(0, s.protocol)) |
| 61 |
|
| 62 |
|
| 63 |
child = rp.FileEntry('x', mode=rp.S_IFREG | 0o644, length=0) |
| 64 |
s.send_data(s.w_ndx(rp.NDX_FLIST_OFFSET - CLEARED_NDX) |
| 65 |
+ child.encode() + rp.end_of_flist(0, s.protocol)) |
| 66 |
s.drain(timeout=2.0) |
| 67 |
s.close() |
| 68 |
|
| 69 |
refused = False |
| 70 |
for _ in range(50): |
| 71 |
new = log.read_text(errors='replace')[len(before):] |
| 72 |
if 'refusing flist for cleared dir_ndx' in new: |
| 73 |
refused = True |
| 74 |
break |
| 75 |
time.sleep(0.1) |
| 76 |
|
| 77 |
if not refused: |
| 78 |
new = log.read_text(errors='replace')[len(before):] |
| 79 |
test_fail( |
| 80 |
"receiver did not refuse a sub-flist for a cleared (duplicate) dir slot " |
| 81 |
"-- it dereferenced the NULL f_name() and crashed.\n" |
| 82 |
f"daemon log:\n{new}") |
| 83 |
|
| 84 |
print("proto-cleared-dirflist: receiver refused a sub-flist for a cleared " |
| 85 |
"dir_flist slot (no NULL-deref crash).") |