Summary
In affected libmosquitto versions, the Will-setting functions do not reject payloads larger than 65,535 bytes. When an oversized payload is supplied, uninitialized heap memory may be included in the Will and transmitted when it is published.
Affected context
The issue occurs in Eclipse's libmosquitto client library when an application calls mosquitto_will_set() or mosquitto_will_set_v5() with a Will payload exceeding 65,535 bytes. Risk depends on whether an application can supply or construct an oversized payload and whether the resulting Will is published to recipients.
Exploit preconditions
- Attack surface: Applications using libmosquitto's Will-setting functions
- Required access: Ability to influence the Will payload, or to cause the application to use an oversized payload
- Trigger point: Setting the Will with a payload longer than 65,535 bytes, followed by publication of the Will
- Why exploitation is possible: The library does not reject the oversized payload, which can result in uninitialized heap bytes being transmitted
Why this happens
The library accepts a payload length beyond the supported 65,535-byte limit without rejecting it. As a result, uninitialized heap memory may be included in data transmitted as the Will. This is an uninitialized resource issue, CWE-908, with potential information disclosure consequences associated with CWE-200.
Potential impact
- Uninitialized heap data may be disclosed to MQTT subscribers
- Sensitive information present in process memory could be exposed
- Applications and services receiving the Will could be affected by unexpected message contents
General mitigation guidance
Defensive patterns include validating Will payload lengths before passing them to the library and enforcing a maximum of 65,535 bytes. Prefer APIs and wrappers that reject out-of-range values by default, and initialize buffers before use. Reduce trust in externally supplied payloads through input limits and validation, and apply least-privilege controls to limit the consequences of any unintended data exposure.
How teams detect issues like this
Review call sites for mosquitto_will_set() and mosquitto_will_set_v5() and check whether payload lengths are bounded before use. Static analysis can flag unchecked lengths passed to these functions and paths where externally influenced data reaches Will configuration. Policy checks can require explicit length validation and tests for boundary and oversized inputs; automated code review tools may help identify these patterns.

