fix: crash in readPublish when payload is 1 byte#4
Open
goyalpalak18 wants to merge 1 commit intohoneynet:mainfrom
Open
fix: crash in readPublish when payload is 1 byte#4goyalpalak18 wants to merge 1 commit intohoneynet:mainfrom
goyalpalak18 wants to merge 1 commit intohoneynet:mainfrom
Conversation
When payloadLen is 1, subtracting 2 from a uint32_t wraps around to 0xFFFFFFFF and writes a null byte way out of bounds, crashing the process. Removed the -2 and unified copyLen for both the memcpy and the null terminator. Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
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.
I found a pretty nasty crash in
servers/mqtt_pit.cinsidereadPublish(). Right now, if the honeypot receives a structurally valid MQTT PUBLISH packet with exactly a 1-byte payload, the entire process dies instantly.What's happening
I noticed that when
payloadLenis 1, thepayloadLen - 2calculation forcopyLenunderflows because it's auint32_t, wrapping around to0xFFFFFFFF.The
memcpyright below it survives because it uses a separate inline clamp, but the null-termination step (payload[copyLen] = '\0';) uses the underflowed index. This attempts to write a null byte about 4 GiB past our 512-byte stack buffer, hitting unmapped memory and triggering aSIGSEGV.Because it crashes instantly, we aren't logging the attacker's IP, and all concurrently tarpitted connections are immediately dropped.
How I fixed it
I removed the
- 2subtraction to prevent the underflow entirely and unified the length logic. Now, both the copy operation and the null-termination use the exact same safely boundedcopyLenvariable.Before:
After:
With this patch, I've made sure 1-byte payloads are safely processed, properly null-terminated, and fully logged without taking down the honeypot.