Code Merge Request #2: Keep the PTY slave open across fork (open)
Merging...
Merged
Something went wrong. Please, merge manually
Checking if merge is possible...
Something went wrong. Please, merge manually
Ryder Lewis wants to merge 1 commit from /u/ryderlewis/sshpass/ to main, 4 days ago
Fixes bug #30, which T Johnson filed in August 2023. T Johnson reported the race and proposed the PTY ordering fix this change builds on. Once merged, this should let the maintainers close the report.
The child can attach and close its PTY slave before the parent opens its own copy. On macOS, the last close can detach the child’s controlling terminal, so the command it starts can fail to open /dev/tty with ENXIO.
The parent now opens the slave with O_NOCTTY before fork(). The child closes the inherited descriptor, then opens and attaches the slave using the existing code. The parent closes its copy if fork() fails. The same code runs on each platform.
Validation
| Platform | Unpatched failures | Patched failures | Patched make check |
|---|---|---|---|
| macOS arm64, Apple Silicon | 69/180 (38.3%) | 0/180 | Pass |
| macOS x86_64 binary, Rosetta on Apple Silicon | 1/180 (0.6%) | 0/180 | Pass |
| Ubuntu 24.04.5 LTS, x86_64 | 0/180 | 0/180 | Pass |
Both comparison builds used the same upstream revision and test code. Every observed unpatched failure was /dev/tty: Device not configured. The stock arm64 binary also failed the new make check test. Rosetta tests the x86_64 binary on the Apple Silicon kernel. A native Intel Mac was unavailable.
The new make check regression runs 18 local dummy-password trials. For the repeated repro, run the following five times per binary. Each batch runs 36 trials with six concurrent processes. No SSH server is needed.
python3 - /path/to/sshpass <<'PY'
from collections import Counter
from concurrent.futures import ThreadPoolExecutor
import subprocess
import sys
prompt = """
sleep 0.02
exec 3<>/dev/tty
printf 'Password: ' >&3
IFS= read -r response <&3
test "$response" = pty-test-response
"""
command = [sys.argv[1], "-d", "0", "/bin/sh", "-ec", prompt]
def trial(_):
result = subprocess.run(
command, input="pty-test-response\n", text=True,
capture_output=True, timeout=5,
)
return result.returncode, result.stderr.strip()
with ThreadPoolExecutor(max_workers=6) as pool:
outcomes = Counter(pool.map(trial, range(36)))
for (status, stderr), count in outcomes.items():
print(f"{count} trials, exit {status}, {stderr or 'no stderr'}")
PY
| Commit | Date | |
|---|---|---|
| 2026-12-01 19:07:59 | Tree |