已合并
fix:update br proxy #12523
fix:update br proxy #12523
已合并
crazy_hu创建于 9月11日
crazy_hu
crazy_hu
9月11日

相关的Issue

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

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

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

日志规范自检:

安全编码自检:

是否已执行L0用例

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 crazy_hu 的贡献)
openharmony_ciopenharmony_ci成员
9月11日 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
9月11日 评论:

感谢提交 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月11日 添加了label:dco检查成功
crazy_hucrazy_hu
9月11日 关联了issue:[新需求]: brproxy补充dfx
byx0010
byx0010成员9月11日进行代码检视2
br_proxy/br_proxy_server_manager.c
已过期
@@ -1305,29 +1305,30 @@
13051305 BrProxyInfo *nodeNext = NULL;
13061306 LIST_FOR_EACH_ENTRY_SAFE(nodeInfo, nodeNext, &(g_proxyList->list), BrProxyInfo, node) {
13071307 if (strcmp(nodeInfo->proxyInfo.brMac, param->brMac) != 0 ||
1308- strcmp(nodeInfo->proxyInfo.uuid, param->uuid) != 0) {
1308+ strcmp(nodeInfo->proxyInfo.uuid, param->uuid) != 0 ||
1309+ nodeInfo->requestId != requestId) {
13091310 continue;
13101311 }
13111312 if (nodeInfo->isConnected && nodeInfo->channel.refresh != NULL) {
@@ -1322,7 +1323,6 @@ static int32_t RefreshChannel(ProxyChannelParam *param, bool *isRefresh, uint32_
13221323static int32_t InitProxyChannelParams(const char *brMac, const char *uuid,
13231324 uint32_t requestId, int32_t appIndex, ProxyChannelParam *param)
13241325{
1325- (void)memset_s(param, sizeof(ProxyChannelParam), 0, sizeof(ProxyChannelParam));
13261326 param->requestId = requestId;
13271327 param->appIndex = appIndex;
13281328 TransBrProxyStorageInfo info;
@@ -1335,7 +1335,7 @@ static int32_t InitProxyChannelParams(const char *brMac, const char *uuid,
13351335 if (strcpy_s(param->brMac, sizeof(param->brMac), brMac) != EOK ||
13361336 strcpy_s(param->uuid, sizeof(param->uuid), uuid) != EOK) {
13371337 TRANS_LOGE(TRANS_SVC, "[br_proxy] copy brMac or uuid failed");
1338- return SOFTBUS_MEM_ERR;
1338+ return SOFTBUS_STRCPY_ERR;
13391339 }
13401340 param->timeoutMs = BR_PROXY_MAX_WAIT_TIME_MS;
13411341 return SOFTBUS_OK;
@@ -1359,15 +1359,20 @@ static int32_t AddChannelAndRefresh(ProxyChannelParam *param, uint32_t oldReques
13591359 }
13601360 if (!isRefresh) {
13611361 ProxyChannelManager *proxyMgr = GetProxyChannelManager();
1362+ if (ret != SOFTBUS_OK) {
byx0010
byx00109月11日评论:

应当判断 proxyMgr 是否为 NULL

likedislike
System
系统消息系统
9月15日 评论:

changed this line on cb011dbf view diff detail

此处折叠了67条消息 查看更多
xuhengxiang
xuhengxiang成员21 天前进行代码检视1
br_proxy/br_proxy_server_manager.c
@@ -872,7 +872,7 @@ static bool IsPidExist(ProxyBaseInfo *baseInfo, uint32_t requestId, pid_t pid)
872872 Anonymize(baseInfo->uuid, &uuidTmp);
873873 TRANS_LOGI(TRANS_SVC,
874874 "[br_proxy] brproxy open! brMac=%{public}s, uuid=%{public}s, requestId=%{public}u, pid=%{public}d",
875- BrMacTmp, uuidTmp, requestId, pid);
875+ AnonymizeWrapper(BrMacTmp), AnonymizeWrapper(uuidTmp), requestId, pid);
876876 AnonymizeFree(BrMacTmp);
877877 AnonymizeFree(uuidTmp);
878878 (void)SoftBusMutexUnlock(&(g_serverList->lock));
@@ -1305,7 +1305,8 @@ static int32_t RefreshChannel(ProxyChannelParam *param, bool *isRefresh, uint32_
13051305 BrProxyInfo *nodeNext = NULL;
13061306 LIST_FOR_EACH_ENTRY_SAFE(nodeInfo, nodeNext, &(g_proxyList->list), BrProxyInfo, node) {
13071307 if (strcmp(nodeInfo->proxyInfo.brMac, param->brMac) != 0 ||
1308- strcmp(nodeInfo->proxyInfo.uuid, param->uuid) != 0) {
1308+ strcmp(nodeInfo->proxyInfo.uuid, param->uuid) != 0 ||
1309+ nodeInfo->requestId != requestId) {
13091310 continue;
13101311 }
13111312 if (nodeInfo->isConnected && nodeInfo->channel.refresh != NULL) {
@@ -1322,7 +1323,6 @@ static int32_t RefreshChannel(ProxyChannelParam *param, bool *isRefresh, uint32_
13221323static int32_t InitProxyChannelParams(const char *brMac, const char *uuid,
13231324 uint32_t requestId, int32_t appIndex, ProxyChannelParam *param)
13241325{
xuhengxiang
xuhengxiang21 天前评论:

从 InitProxyChannelParams 中移除了 memset_s 对 param 的清零操作。虽然当前唯一可见的调用方 ConnectPeerDevice 在调用前添加了 memset_s,但如果存在其他调用方未初始化该结构体,ProxyChannelParam 中未被显式赋值的字段将包含未初始化的栈数据,可能导致未定义行为或数据泄露。

在 InitProxyChannelParams 函数内部保留 memset_s 清零操作以确保防御性安全,或者确保所有调用方在调用前都正确初始化 ProxyChannelParam 结构体。

likedislike
xuhengxiang
xuhengxiang成员21 天前进行代码检视1
tests/dfx/event/unittest/mock/conn_hisysevent_matcher.h
@@ -105,6 +105,9 @@ static int32_t MatchConnEventNameTypeExtraForAddMsg(const HiSysEventParam *param
105105 MatchConnEventNameTypeExtraInt32Param(params, ++index, extra.brProxyIsClear);
106106 MatchConnEventNameTypeExtraInt32Param(params, ++index, extra.brProxyIsRetry);
107107 MatchConnEventNameTypeExtraInt32Param(params, ++index, extra.brProxyIsAcl);
108+ MatchConnEventNameTypeExtraInt32Param(params, ++index, extra.connectReason);
xuhengxiang
xuhengxiang21 天前评论:

新增3次对 params 数组的访问(connectReason、sendCnt、receiveCnt),但未见对 params 数组大小的边界检查。若调用方传入的 params 数组仍按旧的参数数量分配,将导致数组越界读取(buffer over-read),属于内存安全问题。

确认所有调用方传入的 params 数组容量已同步更新以容纳新增的3个参数;或在 MatchConnEventNameTypeExtraInt32Param 中增加对 index 相对于 paramCount 的边界校验。

likedislike
xuhengxiang
xuhengxiang成员21 天前进行代码检视1
dfx/interface/include/form/conn_event_form.h
@@ -80,1 +81,4 @@
8081 EVENT_STAGE_BR_PROXY_SEND = 2112,
82+ 
83+ EVENT_STAGE_FAR_FIELD_START = 2200, // far field stage start[2201,2298]
84+ EVENT_STAGE_FAR_FIELD_END = 2299, // far field stage end[2201,2298]
xuhengxiang
xuhengxiang21 天前评论:

DfxEventExtra 结构体包含 char *func 和 char *hostPkg 裸指针,未定义所有权语义。若该结构体按值传递或浅拷贝,将导致双重释放、释放后使用或内存泄漏。

明确指针所有权:若为字符串字面量/静态字符串,使用 const char*;若需动态分配,提供深拷贝和释放函数,或使用固定长度字符数组替代。

likedislike
xuhengxiang
xuhengxiang成员21 天前进行代码检视1
dfx/interface/include/form/conn_event_form.h
@@ -81,3 +84,4 @@
84+ EVENT_STAGE_FAR_FIELD_END = 2299, // far field stage end[2201,2298]
8185} ConnEventConnectStage;
8286 
8387typedef enum {
xuhengxiang
xuhengxiang21 天前评论:

新增结构体 DfxEventExtra 包含裸指针 char *func 和 char *hostPkg。如果该结构体实例被异步处理(如DFX事件上报)或按值复制,极易导致悬垂指针、Use-After-Free 或双重释放,引发严重崩溃。

避免在跨模块传递的结构体中使用裸指针。建议使用固定长度的字符数组(如 char func[MAX_LEN]),或明确要求调用方保证指针生命周期,并在结构体中增加深拷贝/释放机制。

likedislike
xuhengxiang
xuhengxiang成员21 天前进行代码检视1
dfx/interface/include/form/conn_event_form.h
@@ -158,2 +176,4 @@
158176 int32_t brProxyIsRetry; // BR_PROXY_IS_RETRY
159177 int32_t brProxyIsAcl; // BR_PROXY_IS_ACL
178+ int32_t connectReason; // CONNECT_REASON
179+ int32_t sendCnt; // SEND_CNT
xuhengxiang
xuhengxiang21 天前评论:

在公共接口结构体 ConnEventExtra 末尾添加新字段会破坏ABI兼容性。如果存在新旧版本编译的模块(如动态库与主程序)相互调用,由于结构体大小不一致,会导致内存越界读写,引发崩溃或数据损坏。

如果此头文件用于跨模块/进程通信,不应直接修改现有结构体大小。应通过版本号机制、预留字段或新增的扩展结构体指针来传递额外数据,以确保向后兼容。

likedislike