Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mf01 opened this issue Jan 4, 2024 · 2 comments
Closed

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

mf01 opened this issue Jan 4, 2024 · 2 comments

Comments

@mf01
Copy link

mf01 commented Jan 4, 2024

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 added a commit that referenced this issue Jan 4, 2024
@X-Ryl669
Copy link
Owner

X-Ryl669 commented Jan 4, 2024

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
Copy link
Author

mf01 commented Jan 5, 2024

yes, now it seems to be ok. thanks

@mf01 mf01 closed this as completed Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants