LiamBindle / MQTT-C

A portable MQTT C client for embedded systems and PCs alike.
https://liambindle.ca/MQTT-C
MIT License
766 stars 269 forks source link

Possible undefined behaviour/bad memory access after reconnect #150

Closed perigoso closed 2 years ago

perigoso commented 2 years ago

If within the reconnect callback something fails, and the function returns without correctly initializing the socket and calling connect, the sync continues as if nothing wrong happened, in cases where the socket initialization failed this could mean bad memory accesses in recv

A fix is included in #149

brianrho commented 2 years ago

Yeah, this really was an odd choice -- you've just gotten disconnected from the broker, what makes you so sure that your next reconnection, likely just seconds afterwards, will succeed? The reconnect_callback caller should've been able to deal with failures, without needing the callback itself to block until success.

Wonder if it'll be as simple as modifying the callback to return a bool and then an early return in mqtt_sync() if the callback fails.

perigoso commented 2 years ago

Like i said i already provided a fix, tested and working on real world application