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

fix MQTTDeserialize_unsubscribe didn't judge maxcount or may cause memory access violation #259

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

brucemaclin
Copy link

@brucemaclin brucemaclin commented Mar 2, 2024

an invalid unsubscribe packet in base64 format "rS8BAAABAAAAAAAADGlvdC0wNDBhMDFrcARtcXR0BmlvdGh1YghhbGl5dW5jcwNjbw=="

if set maxcount to 1,and init topicFilters with size 1,*count will bigger than maxcount,topicFilters[*count] cause memory access violation.

@CIPop
Copy link

CIPop commented Mar 4, 2024

We'll also need a UT for validation.

@CIPop CIPop self-assigned this Mar 4, 2024
@CIPop CIPop requested review from CIPop and icraggs March 4, 2024 19:48
Copy link

@CIPop CIPop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparison should be safer (>=) to cover other similar cases.
We would need a UT to exercise the new code.

@@ -81,6 +81,8 @@ int32_t MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid
*count = 0;
while (curdata < enddata)
{
if (*count == maxcount)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>= is safer.

Also, we'll need to scan all other APIs for possible similar issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to >=.But in MQTTV5Deserialize_subscribe,it use *count == maxcount to check.

brucemaclin and others added 2 commits March 5, 2024 12:25
Signed-off-by: brucemaclin <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants