adafruit / Adafruit_MQTT_Library

Arduino library for MQTT support
MIT License
573 stars 291 forks source link

Truncates payload if it doesn't fit in buffer #64

Open oeretana opened 7 years ago

oeretana commented 7 years ago

When function Adafruit_MQTT::publishPacket constructs the MQTT packets to be published, no validation was done to make sure that the function never writes more than MAXBUFFERSIZE into buffer. This could lead to very difficult to debug problems, because the program quickly crashes after writing more than MAXBUFFERSIZE into buffer. This proposed change truncates the payload (only if necessary) to fit buffer. Of course, truncating the payload is still a problem, but it is easier to debug and find. A debug message will let know that the payload was truncated to fit MAXBUFFERSIZE.