Skip to content

Commit 9f3cfef

Browse files
authored
Merge pull request #483 from embhorn/fenrir-fixes
Fix new fenrir reports
2 parents 5873c5e + 4f5c2d2 commit 9f3cfef

17 files changed

Lines changed: 306 additions & 72 deletions

File tree

.github/workflows/sec-websocket-test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ jobs:
5151
mkdir build
5252
cd build
5353
# Note: -Wno-error=sign-conversion works around a sign mismatch in
54-
# libwebsockets v4.3.3 openssl-server.c:311 (lws_filepos_t -> long)
55-
cmake .. -DLWS_WITH_WOLFSSL=1 -DLWS_WOLFSSL_INCLUDE_DIRS=/usr/local/include/wolfssl -DLWS_WOLFSSL_LIBRARIES=/usr/local/lib/libwolfssl.so -DLWS_WITH_EXTERNAL_POLL=1 -DLWS_WITHOUT_TESTAPPS=ON -DCMAKE_C_FLAGS="-Wno-error=sign-conversion"
54+
# libwebsockets v4.3.3 openssl-server.c:311 (lws_filepos_t -> long).
55+
# -Wno-error=incompatible-pointer-types and -Wno-error=discarded-qualifiers
56+
# work around libwebsockets openssl-x509.c calling wolfSSL compat APIs
57+
# with the wrong const/type (fixed on libwebsockets main, not in any release).
58+
cmake .. -DLWS_WITH_WOLFSSL=1 -DLWS_WOLFSSL_INCLUDE_DIRS=/usr/local/include/wolfssl -DLWS_WOLFSSL_LIBRARIES=/usr/local/lib/libwolfssl.so -DLWS_WITH_EXTERNAL_POLL=1 -DLWS_WITHOUT_TESTAPPS=ON -DCMAKE_C_FLAGS="-Wno-error=sign-conversion -Wno-error=incompatible-pointer-types -Wno-error=discarded-qualifiers"
5659
make
5760
sudo make install
5861

examples/aws/awsiot.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,18 +666,24 @@ int awsiot_test(MQTTCtx *mqttCtx)
666666
}
667667
PRINTF("MQTT Subscribe: %s (%d)",
668668
MqttClient_ReturnCodeToString(rc), rc);
669-
if (rc != MQTT_CODE_SUCCESS) {
669+
if (rc != MQTT_CODE_SUCCESS &&
670+
rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
670671
goto disconn;
671672
}
672673

673-
/* show subscribe results */
674+
/* show subscribe results (also reveals which filters the broker
675+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
674676
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
675677
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
676678
PRINTF(" Topic %s, Qos %u, Return Code %u",
677679
topic->topic_filter,
678680
topic->qos, topic->return_code);
679681
}
680682

683+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
684+
goto disconn;
685+
}
686+
681687
/* Publish Topic */
682688
XSNPRINTF((char*)mqttCtx->app_ctx, AWSIOT_PUBLISH_MSG_SZ,
683689
"{\"state\":{\"reported\":{\"hardware\":{\"type\":\"%s\",\"firmware_version\":\"%s\"}}}}",

examples/azure/azureiothub.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,24 @@ int azureiothub_test(MQTTCtx *mqttCtx)
408408
}
409409
PRINTF("MQTT Subscribe: %s (%d)",
410410
MqttClient_ReturnCodeToString(rc), rc);
411-
if (rc != MQTT_CODE_SUCCESS) {
411+
if (rc != MQTT_CODE_SUCCESS &&
412+
rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
412413
goto disconn;
413414
}
414415

415-
/* show subscribe results */
416+
/* show subscribe results (also reveals which filters the broker
417+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
416418
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
417419
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
418420
PRINTF(" Topic %s, Qos %u, Return Code %u",
419421
topic->topic_filter,
420422
topic->qos, topic->return_code);
421423
}
422424

425+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
426+
goto disconn;
427+
}
428+
423429
/* Publish Topic */
424430
XMEMSET(&mqttCtx->publish, 0, sizeof(MqttPublish));
425431
mqttCtx->publish.retain = 0;

examples/firmware/fwclient.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,22 @@ int fwclient_test(MQTTCtx *mqttCtx)
351351
PRINTF("MQTT Subscribe: %s (%d)",
352352
MqttClient_ReturnCodeToString(rc), rc);
353353

354-
if (rc != MQTT_CODE_SUCCESS) {
354+
if (rc != MQTT_CODE_SUCCESS &&
355+
rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
355356
goto disconn;
356357
}
358+
/* show subscribe results (also reveals which filters the broker
359+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
357360
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
358361
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
359362
PRINTF(" Topic %s, Qos %u, Return Code %u",
360363
topic->topic_filter,
361364
topic->qos,
362365
topic->return_code);
363366
}
367+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
368+
goto disconn;
369+
}
364370
/* Read Loop */
365371
PRINTF("MQTT Waiting for message...");
366372
}

examples/mqttclient/mqttclient.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,23 @@ int mqttclient_test(MQTTCtx *mqttCtx)
440440

441441
PRINTF("MQTT Subscribe: %s (%d)",
442442
MqttClient_ReturnCodeToString(rc), rc);
443-
if (rc != MQTT_CODE_SUCCESS) {
443+
if (rc != MQTT_CODE_SUCCESS &&
444+
rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
444445
goto disconn;
445446
}
446447

447-
/* show subscribe results */
448+
/* show subscribe results (also reveals which filters the broker
449+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
448450
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
449451
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
450452
PRINTF(" Topic %s, Qos %u, Return Code %u",
451453
topic->topic_filter,
452454
topic->qos, topic->return_code);
453455
}
456+
457+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
458+
goto disconn;
459+
}
454460
}
455461
else {
456462
PRINTF("MQTT Subscribe: Skipped (-x flag)");

examples/mqttsimple/mqttsimple.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ int mqttsimple_test(void)
410410
mqttObj.subscribe.topic_count = sizeof(topics) / sizeof(MqttTopic);
411411
mqttObj.subscribe.topics = topics;
412412
rc = MqttClient_Subscribe(&mClient, &mqttObj.subscribe);
413+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
414+
PRINTF("MQTT Subscribe Rejected: Topic %s, Return Code %u",
415+
MQTT_TOPIC_NAME, topics[0].return_code);
416+
goto exit;
417+
}
413418
if (rc != MQTT_CODE_SUCCESS) {
414419
goto exit;
415420
}

examples/multithread/multithread.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,19 @@ static void *subscribe_task(void *param)
443443
rc = check_response(mqttCtx, rc, &startSec, MQTT_PACKET_TYPE_SUBSCRIBE,
444444
mqttCtx->cmd_timeout_ms);
445445
} while (rc == MQTT_CODE_CONTINUE);
446-
if (rc != MQTT_CODE_SUCCESS) {
446+
/* SUBSCRIBE_REJECTED means the SUBACK completed normally (some/all
447+
* filters rejected by broker) - no message to cancel in that case. */
448+
if (rc != MQTT_CODE_SUCCESS && rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
447449
MqttClient_CancelMessage(&mqttCtx->client,
448450
(MqttObject*)&mqttCtx->subscribe);
449451
}
450452

451453
PRINTF("MQTT Subscribe: %s (%d)",
452454
MqttClient_ReturnCodeToString(rc), rc);
453455

454-
if (rc == MQTT_CODE_SUCCESS) {
455-
/* show subscribe results */
456+
if (rc == MQTT_CODE_SUCCESS || rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
457+
/* show subscribe results (also reveals which filters the broker
458+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
456459
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
457460
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
458461
PRINTF(" Topic %s, Qos %u, Return Code %u",
@@ -467,6 +470,13 @@ static void *subscribe_task(void *param)
467470
}
468471
#endif
469472

473+
/* Broker rejected the subscription: signal the other threads to stop
474+
* so waitMessage_task (which will never receive the expected messages)
475+
* does not hang this example. */
476+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
477+
mqtt_stop_set();
478+
}
479+
470480
THREAD_EXIT(0);
471481
}
472482

examples/nbclient/nbclient.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,24 @@ int mqttclient_test(MQTTCtx *mqttCtx)
393393

394394
PRINTF("MQTT Subscribe: %s (%d)",
395395
MqttClient_ReturnCodeToString(rc), rc);
396-
if (rc != MQTT_CODE_SUCCESS) {
396+
if (rc != MQTT_CODE_SUCCESS &&
397+
rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
397398
goto disconn;
398399
}
399400

400-
/* show subscribe results */
401+
/* show subscribe results (also reveals which filters the broker
402+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
401403
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
402404
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
403405
PRINTF(" Topic %s, Qos %u, Return Code %u",
404406
topic->topic_filter,
405407
topic->qos, topic->return_code);
406408
}
407409

410+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
411+
goto disconn;
412+
}
413+
408414
/* Publish Topic */
409415
XMEMSET(&mqttCtx->publish, 0, sizeof(MqttPublish));
410416
mqttCtx->publish.retain = 0;

examples/pub-sub/mqtt-sub.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,25 @@ int sub_client(MQTTCtx *mqttCtx)
445445
PRINTF("MQTT Subscribe: %s (%d)",
446446
MqttClient_ReturnCodeToString(rc), rc);
447447
}
448-
if (rc != MQTT_CODE_SUCCESS) {
448+
if (rc != MQTT_CODE_SUCCESS &&
449+
rc != MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
449450
goto disconn;
450451
}
451452

452453
if (mqttCtx->debug_on) {
453-
/* show subscribe results */
454+
/* show subscribe results (also reveals which filters the broker
455+
* rejected when rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) */
454456
for (i = 0; i < mqttCtx->subscribe.topic_count; i++) {
455457
MqttTopic *topic = &mqttCtx->subscribe.topics[i];
456458
PRINTF(" Topic %s, Qos %u, Return Code %u",
457459
topic->topic_filter,
458460
topic->qos, topic->return_code);
459461
}
460462
}
463+
464+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
465+
goto disconn;
466+
}
461467
}
462468
else {
463469
if (mqttCtx->debug_on) {

examples/websocket/websocket_client.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ int main(int argc, char *argv[])
186186
printf("MQTT Subscribe: %s (QoS %d)\n",
187187
topics[0].topic_filter, topics[0].qos);
188188
rc = MqttClient_Subscribe(&client, &subscribe);
189+
if (rc == MQTT_CODE_ERROR_SUBSCRIBE_REJECTED) {
190+
printf("MqttClient_Subscribe rejected: Topic %s, Return Code %u\n",
191+
topics[0].topic_filter, topics[0].return_code);
192+
goto exit;
193+
}
189194
if (rc != MQTT_CODE_SUCCESS) {
190195
printf("MqttClient_Subscribe failed: %d\n", rc);
191196
goto exit;

0 commit comments

Comments
 (0)