knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.78k stars 1.46k forks source link

Memory Corruption because of usage of default move constructor #999

Open 475fe486fb46b1cedca6c5ba354f1c5 opened 1 year ago

475fe486fb46b1cedca6c5ba354f1c5 commented 1 year ago

Missing move constructor and operator= override in class PubSubClient leads to reuse of freed pointer buffer. Which in turn leads to memory corruption when trying to use the object with functions accessing buffer.

Replication:

PubSubClient client = PubSubClient(); // -> Calls default constructor, then copy constructor, then destructor for rvalue behind equals

Expected behavior: Move constructor should copy the old value and replace buffer of old object with 0 so free ignores it