Skip to content

Commit a5f58fb

Browse files
committed
Fix for GCC fuzz build and minor Fenrir reports
1 parent a5dd99f commit a5f58fb

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/mqtt_broker.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void BrokerStore_String(char** dst_ptr,
224224
BrokerStore_String(&(dst), src, len, 1)
225225
#endif
226226

227-
#ifdef ENABLE_MQTT_TLS
227+
#if defined(ENABLE_MQTT_TLS) && !defined(WOLFMQTT_BROKER_CUSTOM_NET)
228228
static int BrokerTls_Init(MqttBroker* broker)
229229
{
230230
WOLFSSL_CTX* ctx = NULL;
@@ -347,7 +347,7 @@ static void BrokerTls_Free(MqttBroker* broker)
347347
}
348348
wolfSSL_Cleanup();
349349
}
350-
#endif /* ENABLE_MQTT_TLS */
350+
#endif /* ENABLE_MQTT_TLS && !WOLFMQTT_BROKER_CUSTOM_NET */
351351

352352
/* -------------------------------------------------------------------------- */
353353
/* wolfIP network backend */
@@ -2657,6 +2657,10 @@ static int BrokerHandle_Connect(BrokerClient* bc, int rx_len,
26572657
rc = MqttDecode_Connect(bc->rx_buf, rx_len, &mc);
26582658
if (rc < 0) {
26592659
WBLOG_ERR(broker, "broker: CONNECT decode failed rc=%d", rc);
2660+
#ifdef WOLFMQTT_V5
2661+
if (mc.props) { (void)MqttProps_Free(mc.props); }
2662+
if (lwt.props) { (void)MqttProps_Free(lwt.props); }
2663+
#endif
26602664
return rc;
26612665
}
26622666

@@ -3848,11 +3852,14 @@ int MqttBroker_Free(MqttBroker* broker)
38483852

38493853
#ifdef ENABLE_MQTT_TLS
38503854
if (broker->tls_ctx != NULL) {
3855+
#if !defined(WOLFMQTT_BROKER_CUSTOM_NET)
38513856
if (broker->tls_ctx_owned) {
38523857
/* Context was created by BrokerTls_Init: full cleanup */
38533858
BrokerTls_Free(broker);
38543859
}
3855-
else {
3860+
else
3861+
#endif
3862+
{
38563863
/* Application-provided TLS context: free ctx but skip
38573864
* wolfSSL_Cleanup() since wolfSSL may be shared */
38583865
wolfSSL_CTX_free(broker->tls_ctx);

src/mqtt_packet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,8 @@ int MqttDecode_Props(MqttPacketType packet, MqttProp** props, byte* pbuf,
646646
tmp = MqttDecode_Vbi(buf, &cur_prop->data_int,
647647
(word32)(buf_len - (buf - pbuf)));
648648
if (tmp < 0) {
649-
return tmp;
649+
rc = tmp;
650+
break;
650651
}
651652
buf += tmp;
652653
total += tmp;

src/mqtt_sn_packet.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ int SN_Decode_Register(byte *rx_buf, int rx_buf_len, SN_Register *regist)
809809
rx_payload += MqttDecode_Num(rx_payload, (word16*)&total_len, (word32)(rx_buf_len - (rx_payload - rx_buf)));
810810
}
811811

812-
if (total_len > rx_buf_len) {
812+
if (total_len >= rx_buf_len) {
813813
return MQTT_TRACE_ERROR(MQTT_CODE_ERROR_OUT_OF_BUFFER);
814814
}
815815
if (total_len < 7) {
@@ -1086,6 +1086,9 @@ int SN_Encode_Publish(byte *tx_buf, int tx_buf_len, SN_Publish *publish)
10861086
*tx_payload++ = flags;
10871087

10881088
/* Encode topic */
1089+
if (publish->topic_name == NULL) {
1090+
return MQTT_TRACE_ERROR(MQTT_CODE_ERROR_BAD_ARG);
1091+
}
10891092
if ((publish->topic_type == SN_TOPIC_ID_TYPE_SHORT) ||
10901093
(publish->topic_type == SN_TOPIC_ID_TYPE_PREDEF)) {
10911094
/* Short and predefined topic names are 2 chars */
@@ -1102,6 +1105,9 @@ int SN_Encode_Publish(byte *tx_buf, int tx_buf_len, SN_Publish *publish)
11021105
tx_payload += MqttEncode_Num(tx_payload, publish->packet_id);
11031106

11041107
/* Encode payload */
1108+
if (publish->total_len > 0 && publish->buffer == NULL) {
1109+
return MQTT_TRACE_ERROR(MQTT_CODE_ERROR_BAD_ARG);
1110+
}
11051111
XMEMCPY(tx_payload, publish->buffer, publish->total_len);
11061112
tx_payload += publish->total_len;
11071113

0 commit comments

Comments
 (0)