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

[HUST CSE][paho-mqtt]PAHO_BUFFER_OVERFLOW #57

Merged
merged 5 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion MQTTClient-RT/paho_mqtt_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,15 @@ int MQTTPublish(MQTTClient *client, const char *topic, MQTTMessage *message)
if (!client->isconnected)
goto exit;

msg_len = sizeof(MQTTMessage) + message->payloadlen + strlen(topic) + 1;

msg_len = sizeof(MQTTMessage) + message->payloadlen + strlen(topicName) + 1;
if(msg_len >= c->buf_size)
{
LOG_E("Message is too long %d:%d.", msg_len, c->buf_size);
d1zzy126 marked this conversation as resolved.
Show resolved Hide resolved
rc = PAHO_BUFFER_OVERFLOW;
goto exit;
}

data = rt_malloc(msg_len);
if (!data)
goto exit;
Expand Down
11 changes: 11 additions & 0 deletions MQTTClient-RT/paho_mqtt_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#endif
#endif

#define DBG_TAG "paho-mqtt"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

static uint16_t pub_port = 7000;

/*
Expand Down Expand Up @@ -971,6 +975,13 @@ int MQTTPublish(MQTTClient *client, const char *topic, MQTTMessage *message)
goto exit;

msg_len = sizeof(MQTTMessage) + message->payloadlen + strlen(topic) + 1;
if(msg_len >= c->buf_size)
d1zzy126 marked this conversation as resolved.
Show resolved Hide resolved
{
LOG_E("Message is too long %d:%d.", msg_len, c->buf_size);
rc = PAHO_BUFFER_OVERFLOW;
goto exit;
}

data = rt_malloc(msg_len);
if (!data)
goto exit;
Expand Down
3 changes: 2 additions & 1 deletion MQTTPacket/src/MQTTConnectClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData

rc = ptr - buf;

exit: FUNC_EXIT_RC(rc);
exit:
FUNC_EXIT_RC(rc);
return rc;
}

Expand Down