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 crash handling publish with invalid predef topic ID. #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions rsmb/src/MQTTSProtocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,16 @@ int MQTTSProtocol_handlePublishes(void* pack, int sock, char* clientAddr, Client
if (origPreDefinedTopicName)
{
expandedPreDefinedTopicName = MQTTSProtocol_replaceTopicNamePlaceholders(client, origPreDefinedTopicName) ;
}

// If original and expanded predef topic names are same, use expanded
// while it is already a copy of orig name
if (strcmp(origPreDefinedTopicName, expandedPreDefinedTopicName) == 0)
{
topicName = expandedPreDefinedTopicName ;
} else {
topicName = malloc(strlen(origPreDefinedTopicName)+1);
strcpy(topicName, origPreDefinedTopicName);
// If original and expanded predef topic names are same, use expanded
// while it is already a copy of orig name
if (strcmp(origPreDefinedTopicName, expandedPreDefinedTopicName) == 0)
{
topicName = expandedPreDefinedTopicName ;
} else {
topicName = malloc(strlen(origPreDefinedTopicName)+1);
strcpy(topicName, origPreDefinedTopicName);
}
}
}
// Short topic names
Expand Down Expand Up @@ -802,6 +802,8 @@ int MQTTSProtocol_handlePubacks(void* pack, int sock, char* clientAddr, Clients*
ListRemove(client->outboundMsgs, m);
/* TODO: msgs counts */
/* (++state.msgs_sent);*/
/* now there is space in the inflight message queue we can process any queued messages */
MQTTProtocol_processQueued(client);
}
}
MQTTSPacket_free_packet(pack);
Expand Down Expand Up @@ -842,6 +844,8 @@ int MQTTSProtocol_handlePubcomps(void* pack, int sock, char* clientAddr, Clients
ListRemove(client->outboundMsgs, m);
/* TODO: msgs counts */
/*(++state.msgs_sent); */
/* now there is space in the inflight message queue we can process any queued messages */
MQTTProtocol_processQueued(client);
}
}
}
Expand Down Expand Up @@ -986,9 +990,17 @@ int MQTTSProtocol_handleSubscribes(void* pack, int sock, char* clientAddr, Clien
// Topic name
if (sub->flags.topicIdType == MQTTS_TOPIC_TYPE_NORMAL && !Topics_hasWildcards(topicName))
{
char* regTopicName = malloc(strlen(topicName)+1);
strcpy(regTopicName, topicName);
topicId = (MQTTSProtocol_registerTopic(client, regTopicName))->id;
ListElement* elem = NULL;
if ((elem = ListFindItem(client->registrations, topicName, registeredTopicNameCompare)) == NULL)
{
char* regTopicName = malloc(strlen(topicName)+1);
strcpy(regTopicName, topicName);
topicId = (MQTTSProtocol_registerTopic(client, regTopicName))->id;
}
else
{
topicId = ((Registration*)(elem->content))->id;
}
}
// Pre-defined topic
else if (sub->flags.topicIdType == MQTTS_TOPIC_TYPE_PREDEFINED)
Expand Down