Reject a packet_buffer_size of 0 instead of accepting it - #3734
Open
afonsojanu wants to merge 1 commit into
Open
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
The websockets_headers_size/packet_buffer_size config option let through a value of 0, which the http__read() path in http_serv.c then treats as an already-allocated, NUL-terminated header buffer: it calls strlen() on it right away and later writes a terminator at packet_buffer[packet_buffer_size - 1]. Neither of those makes sense for a zero-byte buffer, and both read and write past the tiny allocation mosquitto_calloc(1, 0) actually returns. A remote client can trigger this just by connecting to a builtin WebSocket listener configured this way and sending an ordinary HTTP Upgrade request, no MQTT logic involved. Confirmed under AddressSanitizer: a real network request to a broker started with packet_buffer_size 0 produces a deterministic heap-buffer-overflow in strlen() at http_serv.c:85, aborting the broker. The buffer needs at least one byte to ever hold that terminator, so the config parser now rejects 0 the same way it already rejects anything above UINT16_MAX. Added a regression test alongside the existing packet_buffer_size/websockets_headers_size range checks in 16-config-parse-errors-without-tls.py, and updated the wording of the two existing out-of-range tests to match the new message.
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.
The websockets_headers_size/packet_buffer_size config option let through a value of 0, which the http__read() path in http_serv.c then treats as an already-allocated, NUL-terminated header buffer: it calls strlen() on it right away and later writes a terminator at packet_buffer[packet_buffer_size - 1]. Neither of those makes sense for a zero-byte buffer, and both read and write past the tiny allocation mosquitto_calloc(1, 0) actually returns.
A remote client can trigger this just by connecting to a builtin WebSocket listener configured this way and sending an ordinary HTTP Upgrade request, no MQTT logic involved. I confirmed it under AddressSanitizer: a real network request to a broker started with packet_buffer_size 0 produces a deterministic heap-buffer-overflow in strlen() at http_serv.c:85, aborting the broker. The stack trace points straight at the strlen call reading past the 1-byte allocation.
The buffer needs at least one byte to ever hold that terminator, so the fix just tightens the config parser to reject 0 the same way it already rejects anything above UINT16_MAX. Added a regression test alongside the existing packet_buffer_size/websockets_headers_size range checks in 16-config-parse-errors-without-tls.py, and updated the wording of the two existing out-of-range tests since the error message text changed slightly (0 to 1 as the floor).
Ran the full config-parse-errors test file locally, verified the new test fails on unpatched master (reverted just conf.c, kept the test) and passes with the fix restored.
I noticed the CONTRIBUTING guide asks for branches off
develop/fixes, but this repo only hasmasternow, so I branched from there.