803 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

 / 详情

[Bug report] MQTTTopicMatched() access invalid memory

已完成
创建于  
2021-01-06 04:52

该问题是怎么引起的?

The function MQTTTopicMatched() is used to check if packet topic is matched with subscribed one. It tries to check if the first character of the packet topic or the subscribed topic is '$' as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/mqtt/MQTTClient-C/src/MQTTClient.c?_from=gitee_search#L165. The variable topic may be aligned a value to topic_name->lenstring.data as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/mqtt/MQTTClient-C/src/MQTTClient.c?_from=gitee_search#L190. The pointer topic_name gets its value by the function readMQTTLenString() which is called by the function MQTTDeserialize_publish() as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/mqtt/MQTTPacket/src/MQTTDeserializePublish.c?_from=gitee_search#L56. The pointer topic_name->lenstring.data gets value from the pointer pptr, which is the pointer to the output buffer. However, it do not check if the pptr is NULL or 0x0 as shown in https://gitee.com/LiteOS/LiteOS/blob/master/components/connectivity/mqtt/MQTTPacket/src/MQTTPacket.c?_from=gitee_search#L228. If so, the function MQTTTopicMatched() will access invalid memory.

重现步骤

This repo is forbidden to upload a file. Please leave an email and I will send you the packet to trigger this problem.

报错信息

No crash errors, but the system will run into an abnormal status. The developer or tester needs to check this fault by debugging.

评论 (1)

SilentDawn 创建了任务
SilentDawn 关联仓库设置为LiteOS/LiteOS
展开全部操作日志

@SilentDawn
Firstly,the code is from IBM mqtt project, we supposed that it is safe.
Then, let us see the issue,as regarding the following function:
int readMQTTLenString(MQTTString *mqttstring, unsigned char **pptr, unsigned char *enddata)
{

The 2nd parameter is pptr, but the function do not check whether it is a null pointer. We checked the caller, and found that the caller can ensure that the parameter is not null.
curdata --> is suppoed not to be null pointer

unsigned char *curdata = buf;
curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
enddata = curdata + mylen;

*packetid = readInt(&curdata);

*count = 0;
while (curdata < enddata)
{
    if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata))
bing 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS

搜索帮助