| 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 as globmod |
| 25 |
import os |
| 26 |
import time |
| 27 |
|
| 28 |
from rsyncfns import ( |
| 29 |
SCRATCHDIR, claim_ports, require_asan, require_tcp, start_rsyncd, test_fail, |
| 30 |
) |
| 31 |
import rsync_proto as rp |
| 32 |
|
| 33 |
PORT = 12956 |
| 34 |
require_tcp("the pure-Python client needs a real TCP daemon; run with --use-tcp") |
| 35 |
require_asan("the read_args trailing-NULL argv overflow is only observable under " |
| 36 |
"AddressSanitizer") |
| 37 |
claim_ports(PORT) |
| 38 |
|
| 39 |
mod = SCRATCHDIR / 'readargs-mod' |
| 40 |
mod.mkdir(parents=True, exist_ok=True) |
| 41 |
for stale in mod.iterdir(): |
| 42 |
stale.unlink() |
| 43 |
|
| 44 |
|
| 45 |
NFILES = 995 |
| 46 |
for i in range(NFILES): |
| 47 |
(mod / ('f%04d' % i)).write_text('x') |
| 48 |
|
| 49 |
conf = SCRATCHDIR / 'readargs.conf' |
| 50 |
conf.write_text(f"""\ |
| 51 |
pid file = {SCRATCHDIR}/readargs-rsyncd.pid |
| 52 |
use chroot = no |
| 53 |
|
| 54 |
[mod] |
| 55 |
path = {mod} |
| 56 |
read only = no |
| 57 |
""") |
| 58 |
|
| 59 |
asan_log = SCRATCHDIR / 'readargs-asan' |
| 60 |
for stale in globmod.glob(f"{asan_log}.*"): |
| 61 |
os.unlink(stale) |
| 62 |
prev = os.environ.get('ASAN_OPTIONS', '') |
| 63 |
os.environ['ASAN_OPTIONS'] = ( |
| 64 |
(prev + ':' if prev else '') + f'detect_leaks=0:abort_on_error=1:log_path={asan_log}') |
| 65 |
|
| 66 |
start_rsyncd(conf, PORT) |
| 67 |
|
| 68 |
c = rp.DaemonClient('127.0.0.1', PORT) |
| 69 |
|
| 70 |
c.handshake('mod', ['--server', '--sender', '-e.LsfxCIu', '.', '*'], |
| 71 |
greeting_version=30) |
| 72 |
c.drain(timeout=3.0) |
| 73 |
c.close() |
| 74 |
|
| 75 |
reports = '' |
| 76 |
for _ in range(30): |
| 77 |
reports = ''.join(open(r, errors='replace').read() |
| 78 |
for r in globmod.glob(f"{asan_log}.*")) |
| 79 |
if 'AddressSanitizer' in reports: |
| 80 |
break |
| 81 |
time.sleep(0.1) |
| 82 |
|
| 83 |
if 'AddressSanitizer' in reports: |
| 84 |
test_fail( |
| 85 |
"read_args() wrote the trailing argv NULL one slot past the argv heap " |
| 86 |
"allocation when a post-dot glob landed argc exactly on maxargs:\n" |
| 87 |
+ reports[:1500]) |
| 88 |
|
| 89 |
print("io-readargs-argv-nullwrite: the trailing argv NULL stays in bounds when a " |
| 90 |
"post-dot glob fills argv to maxargs.") |