If MqttClient_WaitType() returns early in a nonblock multithread build, the subsequent call to MqttReadStart() will double lock client->lockRecv because it was not checking if a partial read was already in progress.
Fixes ZD17513.
Testing
Build with --enable-stress, with CFLAGS="-DWOLFMQTT_NO_COND_SIGNAL" to use pure mutexes.
Force MqttClient_WaitType to return early, and used a simple lock tracking system to detect and abort on double locks.
Also can be reproduced with valgrind helgrind:
==28242== Thread #1: Attempt to re-lock a non-recursive lock I already hold
==28242== at 0x484D633: mutex_lock_WRK (hg_intercepts.c:934)
==28242== by 0x485278C: pthread_mutex_lock (hg_intercepts.c:960)
==28242== by 0x4860293: wm_SemLock (mqtt_client.c:130)
==28242== by 0x4860435: MqttReadStart (mqtt_client.c:301)
==28242== by 0x4861133: MqttClient_WaitType (mqtt_client.c:1159)
==28242== by 0x4861AAB: MqttClient_Connect (mqtt_client.c:1758)
==28242== by 0x402EC9: multithread_test_init (multithread.c:363)
==28242== by 0x403BDE: multithread_test (multithread.c:759)
==28242== by 0x403F69: main (multithread.c:881)
==28242== Lock was previously acquired
==28242== at 0x484D70A: mutex_lock_WRK (hg_intercepts.c:944)
==28242== by 0x485278C: pthread_mutex_lock (hg_intercepts.c:960)
==28242== by 0x4860293: wm_SemLock (mqtt_client.c:130)
==28242== by 0x4860435: MqttReadStart (mqtt_client.c:301)
==28242== by 0x4861133: MqttClient_WaitType (mqtt_client.c:1159)
==28242== by 0x4861AAB: MqttClient_Connect (mqtt_client.c:1758)
==28242== by 0x402EC9: multithread_test_init (multithread.c:363)
==28242== by 0x403BDE: multithread_test (multithread.c:759)
==28242== by 0x403F69: main (multithread.c:881)
Description
If MqttClient_WaitType() returns early in a nonblock multithread build, the subsequent call to MqttReadStart() will double lock client->lockRecv because it was not checking if a partial read was already in progress.
Fixes ZD17513.
Testing
CFLAGS="-DWOLFMQTT_NO_COND_SIGNAL"
to use pure mutexes.Also can be reproduced with valgrind helgrind: