M13.12: script socket port validation, resource-string trailing commas, parser and socket edge-case tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 09:48:14 -04:00
co-authored by Claude Opus 5.5
parent 88384197f9
commit 2f1788bdf6
3 changed files with 144 additions and 1 deletions
+4 -1
View File
@@ -144,7 +144,10 @@ mod imp {
err(format!("cannot connect to {host}: {last}"))
}
"listen" => {
let port = p.get("port").and_then(J::as_u64).unwrap_or(0) as u16;
let port = match p.get("port").and_then(J::as_f64).unwrap_or(0.0) {
v if v.fract() == 0.0 && (0.0..=65535.0).contains(&v) => v as u16,
v => return err(format!("bad port {v} (0 to 65535)")),
};
match TcpListener::bind(("127.0.0.1", port)).and_then(|l| l.set_nonblocking(true).map(|_| l)) {
Ok(l) => {
let port = l.local_addr().map(|a| a.port()).unwrap_or(port);