eclipse / paho.mqtt.embedded-c

Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)

Home Page:https://eclipse.org/paho

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory corruptions when casting enum to `int *`

maribu opened this issue · 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.

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