main: a port that is not a port is refused, not guessed

atoi() took anything on --mcp-listen-port, --a2a-listen-port and
--openai-listen-port: "abc" bound port 0 (a random port the operator was
never told) and "-5" bound 65531. Both started a server on a port nobody
chose and said nothing.

port_arg() parses with strtol, requires the whole string, and refuses
anything outside 1..65535, naming the option and the value.

Test: tests/test_args.sh, new, in make check. Six bad values are refused
with the reason; a valid port still starts the gateway and says which one
it took. With the check reverted the test reports 6 failures, with it
"test_args: ok". make check: all tests passed.

docs/splinter.1: the two documented port options say so.
This commit is contained in:
lotherk committed 2026-11-23 12:37:42 +00:00
1 parent 0fc81398dc
commit 4ff2844955
4 files changed
+108 -3

No files matched your search

+4
View File
@@ -98,6 +98,8 @@ Beyond 127.x it needs
.Ev SPLINTER_A2A_SERVER_TOKEN .
.It Fl -a2a-listen-port Ar N
A2A port (default 8099).
A port that is not a number between 1 and 65535 is refused before anything
binds.
.It Fl -openai-listen Ar IP
Serve an OpenAI-compatible endpoint
.Pq Pa /v1/chat/completions , /v1/models
@@ -111,6 +113,8 @@ Beyond loopback it needs
.Pa docs/GATEWAY.md .
.It Fl -openai-listen-port Ar N
Gateway port (default 8097).
A port that is not a number between 1 and 65535 is refused before anything
binds.
.It Fl -serve
Serve the engine on a Unix socket instead of drawing a screen.
Each request and event is one JSON object per line; see