Repository navigation
fix(telnet): stop a short NAWS report from crashing the server - #647
Merged
Merged
Conversation
TelnetParseScreenSizePayload checked for at least 3 bytes and then read 4. A NAWS report with only 3 bytes of payload read past its end and panicked on the connection goroutine, which has no recover, so the whole server exited. Any client could trigger it before logging in. Require 4 bytes. Add a table test for the parser and a regression test that sends the short report through TelnetIACHandler.
Volte6
approved these changes
Oct 5, 2026
pruuk
added a commit
to pruuk/DOGMud
that referenced
this pull request
Oct 5, 2026
fix(telnet): port upstream GoMudEngine#647, short NAWS report no longer panics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Any client can crash the server before logging in by sending a 3-byte NAWS (window size) report:
IAC SB NAWS 00 50 00.TelnetParseScreenSizePayloadcheckslen(info) >= 3and then readsinfo[3], which panics withindex out of range [3] with length 3. The parser runs on the connection goroutine, and that goroutine has norecover, so the whole process exits and every connected player is dropped. The off-by-one dates back to the initial commit.TelnetIACHandlerdoes not buffer partial subnegotiations across reads. A normal client whose NAWS reply is split across two reads therefore produces the same short payload.Changes
internal/term/telnet.go:TelnetParseScreenSizePayloadrequires 4 bytes. A shorter report returns the existing error. The caller already handles that error by logging it and keeping the current screen size.internal/term/telnet_test.go(new): table test for the parser.IAC SEthe matcher leaves in.nil.internal/inputhandlers/term_iac_test.go:TestTelnetIACHandlerShortScreenSizeReportsends the 3-byte report throughTelnetIACHandlerand asserts that it does not panic.Test plan
masterwith the panic above and pass with the fix.make validatepasses.go test -race ./...passes.Not in this PR: the connection goroutines (
handleTelnetConnectionand the others) still have no panic guard, so a panic in any other input handler will also end the process.