wolfSSL / wolfMQTT

wolfMQTT is a small, fast, portable MQTT client implementation, including support for TLS 1.3.
https://www.wolfssl.com
GNU General Public License v2.0
518 stars 156 forks source link

Fix double lock of lockRecv. #398

Closed philljj closed 3 months ago

philljj commented 3 months ago

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

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)
philljj commented 3 months ago

Customer is happy with these changes, not waiting on anything else.