CVE-2026-141511: Mongoose: Out-of-Bounds Read in mg_mqtt_next_topic() Leading to Denial of Service
Mongoose is an embedded web server and network library. Prior to 7.22, the Mongoose MQTT broker tutorial's mgmqttnexttopic() function can read two bytes beyond msg->dgram.len when a malformed MQTT SUBSCRIBE packet supplies a topic position that does not leave enough bytes for the topic-length field. Because tutorials/mqtt/mqtt-server/main.c reads that field without validating the complete two-byte access against the datagram boundary, an unauthenticated remote MQTT client can trigger invalid memory access and crash the broker. This issue is fixed in 7.22.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
Mongooseto a version that resolves this vulnerability.Fixed in 7.22
Event History
Frequently Asked Questions
Which deployments are exposed?
Deployments using the Mongoose MQTT broker tutorial code in versions prior to 7.22 are affected. The issue is in tutorials/mqtt/mqtt-server/main.c, not described as affecting every use of the Mongoose library.
What does an attacker need to exploit this?
An unauthenticated remote MQTT client only needs to send a malformed MQTT SUBSCRIBE packet with a topic position that leaves fewer than two bytes for the topic-length field. Successful exploitation can cause invalid memory access and crash the broker.
Is authentication required?
No. The described attack can be performed by an unauthenticated remote MQTT client.
What should be done if the broker cannot be upgraded immediately?
The provided data identifies version 7.22 as the fix. Until upgrading, restrict remote MQTT client access to reduce exposure to malicious malformed SUBSCRIBE packets.
How can I determine whether my deployment is affected?
Check whether your application uses the MQTT broker tutorial implementation, specifically tutorials/mqtt/mqtt-server/main.c, and whether it is based on a Mongoose release earlier than 7.22.