Fixes for MQTT broker found with fuzzing (add fuzzer to CI)#474
Merged
embhorn merged 1 commit intowolfSSL:masterfrom Mar 19, 2026
Merged
Fixes for MQTT broker found with fuzzing (add fuzzer to CI)#474embhorn merged 1 commit intowolfSSL:masterfrom
embhorn merged 1 commit intowolfSSL:masterfrom
Conversation
…sues identified through automated review and fuzz testing.
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.
Summary
Add libFuzzer-based broker fuzzing infrastructure and fix security issues identified through automated review and fuzz testing.
New Features
tests/fuzz/broker_fuzz.c): libFuzzer harness that mocks network callbacks to feed raw MQTT packets into the broker's accept/read/process path viaMqttBroker_Step()tests/fuzz/gen_corpus.py): Python script generating valid and malformed MQTT packets (CONNECT, PUBLISH, SUBSCRIBE, multi-packet sequences, edge cases) as seed inputstests/fuzz/mqtt.dict): libFuzzer dictionary with MQTT protocol constants for intelligent mutationscripts/fuzz.sh): Reusable build-and-run script for local and CI use; accepts duration argument (e.g.,./scripts/fuzz.sh 60for 60 seconds).github/workflows/fuzz.yml): Weekly full run (10 min), PR smoke test (60s), with ASan and crash artifact uploadSecurity Fixes
MqttEncode_Stringword16 truncation (mqtt_packet.c): Strings exceeding 65535 bytes caused a wrapped length prefix while copying full data, leading to protocol desynchronization. AddedMQTT_MAX_UTF8_LENvalidation per MQTT spec.mqtt_packet.c):MqttEncode_Connectadded fulltotal_lentoremain_lenbut truncated toword16inMqttEncode_Data, leaving uninitialized bytes in the packet. Added bounds check.mqtt_broker.c): A second CONNECT on an already-connected session overwrote client state without cleaning up subscriptions. Now disconnects per [MQTT-3.1.0-2].mqtt_broker.c): PUBLISH topic names were not validated for+and#characters. Now rejects per [MQTT-3.3.2-2].$topics (mqtt_broker.c):BrokerTopicMatchdid not filter$-prefixed topics from wildcard filters. Added guard per [MQTT-4.7.2].mqtt_sn_packet.c): Null terminator wrote one byte past buffer end whentotal_len == rx_buf_len. Changed bounds check to>=.mqtt_packet.c):MQTT_DATA_TYPE_VAR_INTerror path usedreturn tmpbypassing property cleanup. Changed torc = tmp; break;consistent with other error paths.mqtt_broker.c): Early return on decode failure leakedmc.propsandlwt.props. Added cleanup before return.mqtt_sn_packet.c): Added NULL validation fortopic_nameandbufferpointers beforeXMEMCPY.Bug Fixes
BrokerTls_Initunused-function error (mqtt_broker.c):--enable-broker --enable-fuzzfailed to compile becauseBrokerTls_Init/BrokerTls_Freewere guarded byENABLE_MQTT_TLSbut only called when!WOLFMQTT_BROKER_CUSTOM_NET. Added matching guard.fuzz.yml):smoke_onlymatrix variable was defined but never used. Added condition so full 10-minute run only triggers on schedule/dispatch.broker_fuzz.c):FUZZ_RESET_INTERVALcheck was dead code since cleanup+init runs every iteration. Removed.Test Plan
make check— all 7 tests pass (--enable-broker --enable-all)./scripts/fuzz.sh 60— clean 60s run, no crashes (clang + ASan)make cleanremovestests/fuzz/corpus/--enable-allnon-fuzz build compiles cleanly