已合并
fix ConvertBtMacToBinary #12528
fix ConvertBtMacToBinary #12528
已合并
wangrui7创建于 9月12日
wangrui7
wangrui7
9月12日

相关的Issue

https://gitcode.com/openharmony/communication_dsoftbus/issues/9791

原因(目的、解决的问题等)

fix ConvertBtMacToBinary

描述(做了什么,变更了什么)

fix ConvertBtMacToBinary

验证结果(新增、改动、可能影响的功能)

fix ConvertBtMacToBinary

日志规范自检:

安全编码自检:

是否已执行L0用例

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 wangrui7 的贡献)
wangrui7wangrui7
9月12日 关联了issue:[Bug]: 修复AI检视ConvertBtMacToBinary意见
openharmony_ciopenharmony_ci成员
9月12日 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
9月12日 评论:

感谢提交 Pull Requests!如果您提交的PR已经开发完毕,请评论 "start build" 触发门禁,更多交互操作,请访问OpenHarmony社区支持命令清单。如果需要调整订阅PR、Issue的变更状态,请访问订阅链接。


Thanks for submitting the pull request. If your Pull Request has already been developed, you can leave a "start build" comment to trigger the gated system. For more commands, please visit OpenHarmony Command List. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
9月12日 添加了label:dco检查成功
JellyAiTudou
JellyAiTudou9月14日进行代码检视2
core/common/utils/softbus_utils.c
@@ -365,2 +370,4 @@
370+ binMac[i] = (uint8_t)val;
365371 token = strtok_r(NULL, BT_ADDR_DELIMITER, &nextTokenPtr);
366372 }
373+ if (token != NULL) {
JellyAiTudou
JellyAiTudou9月14日评论:

这里是校验token != NULL ?通常都是校验==NULL

likedislike
wangrui7
wangrui7
9月16日 评论:

这里token != NULL 代表mac分割已经结束,后面没有字符

此处折叠了52条消息 查看更多
openharmony_ciopenharmony_ci成员
9月17日 删除了label:waiting_for_review
openharmony_ciopenharmony_ci成员
9月17日 添加了label:merged
xuhengxiang
xuhengxiang成员15 天前进行代码检视1
core/common/utils/softbus_utils.c
@@ -361,9 +361,20 @@ int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *bi
361361 SoftBusFree(tmpMac);
xuhengxiang
xuhengxiang15 天前评论:

在转换蓝牙MAC地址到二进制时,未正确处理转换后的值,可能导致数据溢出。

检查strtoul函数的返回值,确保转换后的值不会超过uint8_t类型的最大值。

likedislike
xuhengxiang
xuhengxiang成员15 天前进行代码检视1
core/common/utils/softbus_utils.c
@@ -364,1 +364,3 @@
364- binMac[i] = strtoul(token, &endptr, BT_ADDR_BASE);
364+ unsigned long val = strtoul(token, &endptr, BT_ADDR_BASE);
365+ if (endptr == token || *endptr != '\0' || val > UINT8_MAX) {
366+ COMM_LOGE(COMM_UTILS, "invalid mac addr token: %{public}s", token);
xuhengxiang
xuhengxiang15 天前评论:

在转换蓝牙MAC地址到二进制时,未正确处理最后一个token,可能导致内存泄漏。

在循环结束后检查token是否为NULL,如果不是,则释放tmpMac指针。

likedislike
xuhengxiang
xuhengxiang成员15 天前进行代码检视1
core/common/utils/softbus_utils.c
@@ -362,3 +362,3 @@
362362 return SOFTBUS_ERR;
363363 }
364- binMac[i] = strtoul(token, &endptr, BT_ADDR_BASE);
364+ unsigned long val = strtoul(token, &endptr, BT_ADDR_BASE);
xuhengxiang
xuhengxiang15 天前评论:

缺少对 MAC 地址段数不足的检查。如果输入的 MAC 地址段数少于预期(例如 "11:22:33"),循环内 token 将变为 NULL,传递给 strtoul 会导致空指针解引用崩溃;或者如果循环提前退出,会导致 binMac 缓冲区未完全初始化。代码只增加了对段数过多(token != NULL)的检查,遗漏了段数不足的情况。

在循环内增加对 token == NULL 的检查,如果段数不足,应释放内存并返回错误;或者在循环结束后检查已解析的段数是否等于预期长度。

likedislike