| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
import glob |
| 25 |
import os |
| 26 |
|
| 27 |
from rsyncfns import ( |
| 28 |
SCRATCHDIR, claim_ports, require_asan, require_tcp, start_rsyncd, test_fail, |
| 29 |
) |
| 30 |
import rsync_proto as rp |
| 31 |
|
| 32 |
PORT = 12951 |
| 33 |
require_tcp("the pure-Python generator needs a real TCP daemon; run with --use-tcp") |
| 34 |
require_asan("the hash_search want_i NULL-deref is observed via the daemon's " |
| 35 |
"AddressSanitizer SEGV report") |
| 36 |
claim_ports(PORT) |
| 37 |
|
| 38 |
mod = SCRATCHDIR / 'wanti-mod' |
| 39 |
mod.mkdir(parents=True, exist_ok=True) |
| 40 |
CONTENT = b'A' |
| 41 |
(mod / 'f').write_bytes(CONTENT) |
| 42 |
LEN = len(CONTENT) |
| 43 |
|
| 44 |
conf = SCRATCHDIR / 'wanti.conf' |
| 45 |
conf.write_text(f"""\ |
| 46 |
pid file = {SCRATCHDIR}/wanti-rsyncd.pid |
| 47 |
use chroot = no |
| 48 |
|
| 49 |
[mod] |
| 50 |
path = {mod} |
| 51 |
read only = no |
| 52 |
""") |
| 53 |
|
| 54 |
asan_log = SCRATCHDIR / 'wanti-asan' |
| 55 |
for stale in glob.glob(f"{asan_log}.*"): |
| 56 |
os.unlink(stale) |
| 57 |
prev = os.environ.get('ASAN_OPTIONS', '') |
| 58 |
os.environ['ASAN_OPTIONS'] = ( |
| 59 |
(prev + ':' if prev else '') + f'detect_leaks=0:abort_on_error=1:log_path={asan_log}') |
| 60 |
|
| 61 |
start_rsyncd(conf, PORT) |
| 62 |
|
| 63 |
c = rp.DaemonClient('127.0.0.1', PORT) |
| 64 |
|
| 65 |
c.handshake('mod', ['--server', '--sender', '-e.LsfxCIu', '.', 'mod/f'], |
| 66 |
greeting_version=30) |
| 67 |
entries = rp.sort_entries(c.recv_flist(preserve_links=False)) |
| 68 |
ndx = next(i for i, e in enumerate(entries) if e.name == b'f') |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
sum1 = rp.get_checksum1(CONTENT) |
| 73 |
req = (c.w_ndx(ndx) + rp.w_shortint(rp.ITEM_TRANSFER) |
| 74 |
+ rp.w_sum_head(2, LEN + 1, 0, LEN) |
| 75 |
+ rp.w_int(sum1) + rp.w_int(sum1)) |
| 76 |
c.send_data(req) |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
c.send_data(c.w_ndx(rp.NDX_DONE)) |
| 81 |
c.drain(timeout=3.0) |
| 82 |
c.close() |
| 83 |
|
| 84 |
reports = glob.glob(f"{asan_log}.*") |
| 85 |
text = ''.join(open(r, errors='replace').read() for r in reports) |
| 86 |
if 'AddressSanitizer' in text: |
| 87 |
test_fail( |
| 88 |
"daemon sender hit an AddressSanitizer error on a forged adjacent-match " |
| 89 |
"sum header -- check_want_i substituted want_i without re-checking its " |
| 90 |
"length, so map_ptr() returned NULL and hash_search dereferenced it:\n" |
| 91 |
+ text[:1500]) |
| 92 |
|
| 93 |
print("match-want-i-nolen: forged want_i adjacent match is length-checked; no " |
| 94 |
"NULL-deref in hash_search.") |