Skip to content

Commit 73ccdb3

Browse files
committed
Fix CI segfault and address PR #480 review comments
- Fix unit test SIGSEGV on macOS: call MqttProps_Init/ShutDown for v5 static property pool semaphore initialization - Use xfer instead of client->write.len for tx_buf clearing (write.len is zeroed by MqttWriteStop before the XMEMSET) - Free decoded v5 props in roundtrip test to prevent pool exhaustion - Remove unused T24_PLUS_RC/T24_HASH_RC variables in broker.test - Change TLS credential warning guard from WOLFMQTT_DEBUG_CLIENT to DEBUG_WOLFMQTT for broader coverage
1 parent ef759aa commit 73ccdb3

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

scripts/broker.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,11 +940,9 @@ wait_for_file "${TMP_DIR}/t24_sub.ready" 5
940940
# Attempt to PUBLISH with '+' in the topic name (must be rejected by broker)
941941
./$pub_bin -T -h 127.0.0.1 -p $port -n "test/+/card" -m "bad_wildcard_plus" \
942942
>"${TMP_DIR}/t24_pub_plus.log" 2>&1
943-
T24_PLUS_RC=$?
944943
# Attempt to PUBLISH with '#' in the topic name (must be rejected by broker)
945944
./$pub_bin -T -h 127.0.0.1 -p $port -n "test/#" -m "bad_wildcard_hash" \
946945
>"${TMP_DIR}/t24_pub_hash.log" 2>&1
947-
T24_HASH_RC=$?
948946
sleep 0.3
949947
kill $T24_SUB_PID 2>/dev/null
950948
wait $T24_SUB_PID 2>/dev/null || true

src/mqtt_client.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ int MqttClient_Connect(MqttClient *client, MqttConnect *mc_connect)
16641664
}
16651665

16661666
if (mc_connect->stat.write == MQTT_MSG_BEGIN) {
1667-
#ifdef WOLFMQTT_DEBUG_CLIENT
1667+
#ifdef DEBUG_WOLFMQTT
16681668
/* Warn if credentials are being sent without TLS */
16691669
if ((mc_connect->username != NULL || mc_connect->password != NULL) &&
16701670
!(MqttClient_Flags(client, 0, 0) & MQTT_CLIENT_FLAG_IS_TLS)) {
@@ -1728,8 +1728,9 @@ int MqttClient_Connect(MqttClient *client, MqttConnect *mc_connect)
17281728
#endif
17291729
MqttWriteStop(client, &mc_connect->stat);
17301730

1731-
/* Clear tx_buf to remove any plaintext credentials from memory */
1732-
XMEMSET(client->tx_buf, 0, client->write.len);
1731+
/* Clear tx_buf to remove any plaintext credentials from memory.
1732+
* Use xfer (saved before MqttWriteStop zeroes client->write) */
1733+
XMEMSET(client->tx_buf, 0, xfer);
17331734

17341735
if (rc != xfer) {
17351736
MqttClient_CancelMessage(client, (MqttObject*)mc_connect);

tests/unit_test.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ static void test_publish_resp_v5_roundtrip(void)
352352
"v5 PUBACK SUCCESS+props: packet_id roundtrip");
353353
CHECK(dec.reason_code == MQTT_REASON_SUCCESS,
354354
"v5 PUBACK SUCCESS+props: reason_code roundtrip");
355+
if (dec.props) {
356+
MqttProps_Free(dec.props);
357+
dec.props = NULL;
358+
}
355359

356360
/* Case: reason_code=non-SUCCESS, props=NULL (baseline, should work) */
357361
XMEMSET(&enc, 0, sizeof(enc));
@@ -584,6 +588,10 @@ int main(int argc, char** argv)
584588

585589
PRINTF("wolfMQTT Unit Tests");
586590

591+
#ifdef WOLFMQTT_V5
592+
MqttProps_Init();
593+
#endif
594+
587595
test_vbi();
588596
test_encode_publish();
589597
test_decode_connack();
@@ -596,6 +604,7 @@ int main(int argc, char** argv)
596604
test_decode_unsuback();
597605
#ifdef WOLFMQTT_V5
598606
test_publish_resp_v5_roundtrip();
607+
MqttProps_ShutDown();
599608
#endif
600609

601610
PRINTF("=== Results: %d/%d passed ===",

0 commit comments

Comments
 (0)