paho.mqtt.embedded-c icon indicating copy to clipboard operation
paho.mqtt.embedded-c copied to clipboard

Memory corruptions when casting enum to `int *`

Open maribu opened this issue 3 years ago • 1 comments

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.

maribu avatar Jan 11 '22 17:01 maribu