fix: silently drop short GS4 query datagrams - #1857
Open
bejiihiu wants to merge 1 commit into
Open
Conversation
GameSpyQueryHandler.channelRead0 reads magic bytes, type, and sessionId without checking readableBytes first. A malformed UDP datagram shorter than 7 bytes throws IndexOutOfBoundsException, spamming the log. Adds MINIMUM_MESSAGE_LENGTH constant (7) with a readable guard at the top of channelRead0. Also guards the challenge-token read in the STAT branch (4 bytes after the 7-byte header) for defence in depth. Fixes PaperMC#1828
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.
Fixes #1828.
GameSpyQueryHandler.channelRead0reads magic bytes, type, and sessionId without first checkingreadableBytes(). A malformed UDP datagram shorter than 7 bytes throwsIndexOutOfBoundsExceptionon every packet, caught and logged at WARNING:Fix:
MINIMUM_MESSAGE_LENGTH(7) — a named constant with javadoc explaining the 2+1+4 byte layout and which handler branch reads the shortest valid message (QUERY_TYPE_HANDSHAKE).MINIMUM_MESSAGE_LENGTHbefore touching any byte.QUERY_TYPE_STATbranch (4 bytes after the 7-byte header) for defence-in-depth — a 7-byte datagram with type0x00would pass the header check but fail on thereadInt()for the challenge token.Test coverage:
Validation:
./gradlew :velocity-proxy:check— checkstyle, spotless, and all tests pass