X-Ryl669 / eMQTT5

An embedded MQTTv5 client in C++ with minimal footprint, maximal performance
MIT License
65 stars 14 forks source link

readFrom() return BadData for 4-byte buffer #17

Closed mf01 closed 10 months ago

mf01 commented 10 months ago

In [0] there is the check of the variable byte integer buffer length

uint32 readFrom(const uint8 * buffer, uint32 bufLength)
{
    for (size = 0; size < 4;)
    {
        if ((uint32)(size+1) > bufLength) return NotEnoughData;
        value[size] = buffer[size];
        if (value[size++] < 0x80) break;
    }
    return size < 4 ? size : (uint32)BadData;
}

for buffer = {0x8c, 0xda, 0xc4, 0x09} and bufLength = 4 this will result in BadData but it should be a valid input. Is the return condition correct?

[0] https://github.com/X-Ryl669/eMQTT5/blob/2f261615d3c2adc5e0c273876cfb35a0c7304b95/lib/include/Protocol/MQTT/MQTT.hpp#L692C31-L692C31

X-Ryl669 commented 10 months ago

You're right, the condition is too restricted.

I believe the last commit should have fixed it. Please confirm it's ok for you.

mf01 commented 10 months ago

yes, now it seems to be ok. thanks