-
Notifications
You must be signed in to change notification settings - Fork 274
fix:fixed crash issues when the illegal topic is received #117
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
Conversation
fix:fixed crash issues when the illegal topic is received
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes segmentation fault issues when receiving illegal MQTT topics by rewriting the topic matching logic and adding null pointer safety checks to list operations.
- Complete rewrite of
mqtt_topic_is_matched
function with improved wildcard handling and input validation - Added null pointer checks to list deletion operations to prevent crashes
- Removed unused variable assignment in MQTT deserialize function
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
mqttclient/mqttclient.c | Rewrote topic matching algorithm and added safety checks to message handler destruction |
mqtt/MQTTDeserializePublish.c | Removed unused variable assignment in publish deserialization |
common/mqtt_list.c | Added null pointer validation and cleanup in list deletion function |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
mqtt_list_del(&msg_handler->list); | ||
msg_handler->list.prev == NULL; | ||
msg_handler->list.next == NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line uses comparison operator '==' instead of assignment operator '='. Should be 'msg_handler->list.prev = NULL;'
msg_handler->list.next == NULL; | |
msg_handler->list.prev = NULL; | |
msg_handler->list.next = NULL; |
Copilot uses AI. Check for mistakes.
mqtt_list_del(&msg_handler->list); | ||
msg_handler->list.prev == NULL; | ||
msg_handler->list.next == NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line uses comparison operator '==' instead of assignment operator '='. Should be 'msg_handler->list.next = NULL;'
msg_handler->list.next == NULL; | |
msg_handler->list.prev = NULL; | |
msg_handler->list.next = NULL; |
Copilot uses AI. Check for mistakes.
platform_memory_free(msg_handler); | ||
msg_handler = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the local parameter 'msg_handler' to NULL has no effect outside this function since parameters are passed by value. This assignment is ineffective.
msg_handler = NULL; |
Copilot uses AI. Check for mistakes.
nextpos = ++curn + 1; | ||
const char* filter = topic_filter; | ||
const char* topic = topic_name->lenstring.data; | ||
int topic_len = topic_name == NULL || topic_name->lenstring.data == NULL || topic_name->lenstring.len <= 0 ? 0 : strnlen(topic, topic_name->lenstring.len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'topic' is assigned from 'topic_name->lenstring.data' before checking if 'topic_name' is NULL. This could cause a segmentation fault if 'topic_name' is NULL.
int topic_len = topic_name == NULL || topic_name->lenstring.data == NULL || topic_name->lenstring.len <= 0 ? 0 : strnlen(topic, topic_name->lenstring.len); | |
const char* topic = NULL; | |
int topic_len = 0; | |
if (topic_name != NULL && topic_name->lenstring.data != NULL && topic_name->lenstring.len > 0) { | |
topic = topic_name->lenstring.data; | |
topic_len = strnlen(topic, topic_name->lenstring.len); | |
} |
Copilot uses AI. Check for mistakes.
const char* filter = topic_filter; | ||
const char* topic = topic_name->lenstring.data; | ||
int topic_len = topic_name == NULL || topic_name->lenstring.data == NULL || topic_name->lenstring.len <= 0 ? 0 : strnlen(topic, topic_name->lenstring.len); | ||
int filter_len = strlen(filter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't validate that 'topic_filter' parameter is not NULL before calling strlen(). This could cause a segmentation fault if 'topic_filter' is NULL.
Copilot uses AI. Check for mistakes.
Rewritten mqtt_topic_is_matched and fixed Segmentation fault