OpenAtomFoundation / TobudOS

开放原子开源基金会孵化的物联网操作系统,捐赠前为腾讯物联网终端操作系统TencentOS Tiny
https://cloud.tencent.com/product/tos-tiny
5.97k stars 1.61k forks source link

[HUST CSE]Modify the null pointer fifo to access first and then judge #368

Closed Eric-hust closed 1 year ago

Eric-hust commented 1 year ago

1.为什么提交这份PR (why to submit this PR) 在/components/connectivity/mqttclient/common/log/fifo.c这个文件中,第101行

salof_sem_pend(fifo->sem, timeout);

if((!fifo) || (!buff) || (!len))
    return 0;

这处代码首先进行salof_sem_pend(fifo->sem, timeout)再进行判断fifo是否为空有问题,如果fifo为空,则访问其成员变量会导致未定义的行为。

2.你的解决方案是什么 (what is your solution) 应该先检查传入的salof_fifo_t类型的参数fifo是否为空(即是否为NULL),然后才能使用它的成员变量。因此,应该将if((!fifo) || (!buff) || (!len))这个语句的判断移到salof_sem_pend(fifo->sem, timeout)之前。

3.在什么测试环境下测试通过 (what is the test environment) all

tencent-adm commented 1 year ago

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.