已合并
告警修复 #5576
已合并
王旭创建于 10 天前
王旭
王旭
10 天前

一、内容说明(相关的Issue)

二、建议测试周期和提测地址

建议测试完成时间:xxxx.xx.xx
投产上线时间:xxxx.xx.xx
提测地址:CI环境/压测环境
测试账号:

三、变更内容

  • 3.1 关联PR列表

  • 3.2 数据库和部署说明

    1. 常规更新
    2. 重启unicorn
    3. 重启sidekiq
    4. 迁移任务:是否有迁移任务,没有写 "无"
    5. rake脚本:bundle exec xxx RAILS_ENV = production;没有写 "无"
  • 3.4 其他技术优化内容(做了什么,变更了什么)

    • 重构了 xxxx 代码
    • xxxx 算法优化
  • 3.5 废弃通知(什么字段、方法弃用?)

  • 3.6 后向不兼容变更(是否有无法向后兼容的变更?)

四、研发自测点(自测哪些?冒烟用例全部自测?)

自测测试结论:

五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)

检查点:

需求名称 是否影响xx公共模块 是否需要xx功能 需求升级是否依赖其他子产品
xxx 需要 不需要

接口测试:

性能测试:

并发测试:

其他:

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 王旭 的贡献)
openharmony_ciopenharmony_ci成员
10 天前 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
10 天前 评论:

感谢提交 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成员
10 天前 添加了label:dco检查成功
王旭王旭
10 天前 关联了issue:[Bug]: 告警修复
王旭
王旭
10 天前 评论:

start build

likedislike
openharmony_ci
openharmony_ci成员
10 天前 评论:

首次触发
门禁构建开始,包含静态检查、代码编译和测试【dayu600_7885测试, dayu200测试, dayu200_tdd编译, master_inner_build编译, hispark_pegasus测试, hispark_pegasus_3863测试, dayu600_7885编译, hispark_pegasus编译, x86_64_virt编译, dayu200编译, hispark_taurus_Linux编译, ohos-host_mini_tdd编译, hispark_pegasus_3863编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6a8d797864650f998bd834b3/runlist

likedislike
LisaMessi
10 天前 评论:

PR 审查报告:#5576 - 告警修复

仓库:OpenHarmony/communication_wifi
PR 地址https://gitcode.com/openharmony/communication_wifi/merge_requests/5576
作者:王旭 (tradeWindToNorth)
目标分支:master
PR SHA6c1fba641847a2870ed54234dd8b230c9016605b
状态:open
标签waiting_on_authordco检查成功

CI 状态

  • ✅ DCO 检查成功
  • ✅ 冲突检查通过

变更概要

本 PR 修复 P2P DNS-SD 响应解析中的静态检查告警(未初始化内存读取),涉及 1 个文件(+6/-4),两处同类修改:

FetchDnsName

// 修改前:分配 t 字节,固定按 t 长度追加(短读时读到未初始化内存)
std::unique_ptr<char[]> ptr = std::make_unique<char[]>(t);
istream.read(ptr.get(), t);
dnsName.append(ptr.get(), 0, t);

// 修改后:分配 t+1 并写 NUL 终止符,按实际读取字节数追加
std::unique_ptr<char[]> ptr = std::make_unique<char[]>(t + 1);
istream.read(ptr.get(), t);
ptr[t] = '\0';
dnsName.append(ptr.get(), static_cast<std::string::size_type>(istream.gcount()));

ParseDatasvrNameLength 同模式修复。


问题详情

⚠️主要

1. 短读场景行为变化需确认(语义已修复,但属行为变更)

位置FetchDnsName / ParseData

描述istream.read() 遇到 EOF/流结束时 gcount() 返回实际读取字节数(可能小于请求长度)。修改前 append(ptr.get(), 0, t) 固定追加 t 字节,短读时会读取未初始化内存(这正是告警来源);修改后按 gcount() 追加,行为更安全、更合理。

影响:短读时输出从"含垃圾字节"变为"截断名称"——这是行为变更,依赖方(DNS-SD 服务发现)看到的名称可能与之前不同,需确认无兼容性依赖。

修复建议:确认该行为变更可接受(推荐),并在 PR 描述中说明。另可简化——gcount() 已保证安全,NUL 终止符为防御性冗余:

std::unique_ptr<char[]> ptr = std::make_unique<char[]>(t);
istream.read(ptr.get(), t);
dnsName.append(ptr.get(), static_cast<std::string::size_type>(istream.gcount()));

(保留 t + 1 + NUL 亦可,作为防御性编程可接受,但需说明意图。)


2. EOF 时 tellg() 下溢检查为既有残留问题

位置FetchDnsName 开头

描述

if (t > (istream.str().size() - static_cast<unsigned char>(istream.tellg()))) {
    return false;
}

istream 已处于 EOF,tellg() 返回 -1,static_cast<unsigned char>(-1) = 255,size() - 255 在无符号运算下下溢为巨大值,长度检查失效。此问题为既有代码(不在本次 diff 内),但本次修改涉及同一解析路径,建议一并修复。

影响:EOF 场景下长度校验失效(虽然后续 gcount() 已限制读取,风险降低,但校验形同虚设)。

修复建议

std::streampos pos = istream.tellg();
if (pos < 0 || t > (istream.str().size() - static_cast<size_t>(pos))) {
    return false;
}

💡建议

3. 其他小项

  • 两处修改模式一致,建议提取公共辅助函数(如 ReadCString(istream, len))避免重复;
  • 无测试变更:建议补充 DNS-SD 响应解析的单测(含短读/EOF 边界用例),防止回归;
  • PR 描述为空模板,未说明触发告警的静态检查工具与告警原文。

总体评分

维度 评分 说明
功能正确性 7/10 修复方向正确,短读行为变更需确认
代码质量 7/10 修改简洁,可提取公共函数
安全性 8/10 消除未初始化内存读取
可维护性 6/10 说明缺失
测试充分性 4/10 无测试变更
综合评分 7/10

审查结论

建议操作:⚠️ 有条件合并

建议修复:

  • 问题 1:确认短读行为变更可接受;
  • 问题 2:顺带修复 tellg() 下溢校验(同一解析路径)。

优点:

  • 修复方向正确:gcount() 按实际读取长度追加,消除未初始化内存读取告警
  • 两处同类问题一并修复,模式一致
  • 边界防护(短读、NUL 终止)考虑周全
  • DCO 检查通过
likedislike
openharmony_ciopenharmony_ci成员
10 天前 添加了label:编译成功
openharmony_ciopenharmony_ci成员
10 天前 添加了label:静态检查成功
openharmony_ciopenharmony_ci成员
10 天前 添加了label:冒烟测试成功
openharmony_ciopenharmony_ci成员
10 天前 通过测试
openharmony_ci
openharmony_ci成员
10 天前 评论:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6a8d797864650f998bd834b3/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result test result package
1 hispark_taurus_Linux success NA >>>
2 dayu200 success success >>>
3 dayu200_tdd success NA >>>
4 hispark_pegasus success success >>>
5 master_inner_build success(IGNORE) NA >>>
6 ohos-host_mini_tdd success NA >>>
7 dayu600_7885 success success >>>
8 x86_64_virt success NA >>>
9 hispark_pegasus_3863 success success >>>

likedislike
openharmony_ciopenharmony_ci成员
10 天前 删除了label:waiting_on_author
openharmony_ciopenharmony_ci成员
10 天前 添加了label:waiting_for_review
openharmony_ci
openharmony_ci成员
10 天前 评论:

您好,Committer @wshixjr @bjtu_wujun_transportation @f00651013 @chengguohong ,请分配检视人员检视该PR,可以通过命令"assign [@someone_id]"分配检视人员,也可以直接评论"assign"分配给自己进行检视。


Hello, Committer @wshixjr @bjtu_wujun_transportation @f00651013 @chengguohong . Please assign someone to review the PR. You can assign a reviewer by using the command "assign [@someone_id]", or you can comment "assign" to review the PR by yourself.

likedislike
wujunwujun成员
9 天前 通过审查
openharmony_ci
openharmony_ci成员
9 天前 评论:

验证结果已超过12小时,之前验证结果无效,自动重新触发构建,请关注最新验证结果

likedislike
openharmony_ci
openharmony_ci成员
9 天前 评论:

start build

likedislike
openharmony_ciopenharmony_ci成员
9 天前 删除了label:编译成功
openharmony_ciopenharmony_ci成员
9 天前 删除了label:静态检查成功
openharmony_ciopenharmony_ci成员
9 天前 删除了label:冒烟测试成功
openharmony_ci
openharmony_ci成员
9 天前 评论:

本地或库上代码有更新,全量重新构建,重置所有关联PR的验证状态
门禁构建开始,包含静态检查、代码编译和测试【dayu200_tdd编译, hispark_pegasus_3863测试, x86_64_virt编译, dayu200测试, hispark_pegasus_3863编译, hispark_taurus_Linux编译, hispark_pegasus测试, master_inner_build编译, hispark_pegasus编译, dayu600_7885编译, dayu600_7885测试, ohos-host_mini_tdd编译, dayu200编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6a8eb0fd64650f998b38c719/runlist

likedislike
openharmony_ciopenharmony_ci成员
9 天前 添加了label:编译成功
openharmony_ciopenharmony_ci成员
9 天前 添加了label:静态检查成功
openharmony_ciopenharmony_ci成员
9 天前 添加了label:冒烟测试成功
openharmony_ciopenharmony_ci成员
9 天前 通过测试
openharmony_ci
openharmony_ci成员
9 天前 评论:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6a8eb0fd64650f998b38c719/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result test result package
1 hispark_taurus_Linux success NA >>>
2 dayu200 success success >>>
3 dayu200_tdd success NA >>>
4 hispark_pegasus success success >>>
5 master_inner_build failed(IGNORE)(代码同步失败) NA >>>
6 ohos-host_mini_tdd success NA >>>
7 dayu600_7885 success success >>>
8 x86_64_virt success NA >>>
9 hispark_pegasus_3863 success success >>>

likedislike
openharmony_ci
openharmony_ci成员
9 天前 评论:

您好,Committer @wshixjr @bjtu_wujun_transportation @f00651013 @chengguohong ,请分配检视人员检视该PR,可以通过命令"assign [@someone_id]"分配检视人员,也可以直接评论"assign"分配给自己进行检视。


Hello, Committer @wshixjr @bjtu_wujun_transportation @f00651013 @chengguohong . Please assign someone to review the PR. You can assign a reviewer by using the command "assign [@someone_id]", or you can comment "assign" to review the PR by yourself.

likedislike
openharmony_ciopenharmony_ci成员
9 天前 关闭了关联的issue
openharmony_ciopenharmony_ci成员
9 天前 合入了pull request,合并节点 SHA:aafa86303222af16198f81c5a5228a8f3cd46d0c
openharmony_ciopenharmony_ci成员
9 天前 删除了label:waiting_for_review
openharmony_ciopenharmony_ci成员
9 天前 添加了label:merged