eclipse / paho.mqtt.embedded-c

Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)
https://eclipse.org/paho
Other
1.35k stars 752 forks source link

Memory corruptions when casting enum to `int *` #233

Open maribu opened 2 years ago

maribu commented 2 years ago

RIOT-OS is packaging this repo downstream. I just opened a PR to fix a memory corruption bug downstream that still seems to be present here.

The issue is relatively trivial: The C standard doesn't say which size an enum has, only that it needs to be large enough to hold all constants defined in that enum. So sizeof(enum QoS) == sizeof(int) - as assumed in this library - is not generally correct. Casting a pointer to enum QoS to int * and passing this to a function that accesses this int * could e.g. result in a 32 bit memory access of an 8 bit value.

This issue might be something you want to fix soonish.

icraggs commented 1 year ago

Thank you. This was fixed in commit: e233d994 albeit in a slightly different way.