已合并
fix(liveview): CheckNotificationRequest 增加空 content 判空校验防止崩溃 #5012
fix(liveview): CheckNotificationRequest 增加空 content 判空校验防止崩溃 #5012
已合并
stepend98创建于 8月25日
stepend98
stepend98
8月25日

变更说明

NotificationRequest::CheckNotificationRequest 在 IsCommonLiveView() 返回 true 后直接解引用 notificationContent_,未校验指针有效性。IsCommonLiveView() 仅比较 slotType_ 和 notificationContentType_ 两个枚举值,不验证 notificationContent_ 是否指向有效对象。

触发路径

  • IPC 反序列化:ReadFromParcel 先读取 notificationContentType_(LIVE_VIEW 合法),后读取 content 的 valid 标志;valid=false 时不读取 content 对象,notificationContent_ 保持 nullptr,但反序列化返回 true。后续服务端 publish 流程 Filter() → CheckNotificationRequest() 触发空指针解引用
  • JSON 反序列化:ConvertJsonToEnum 设置类型,ConvertJsonToNotificationContent 无 "content" 键时 notificationContent_ 保持 nullptr,同样触发

修复内容

  • CheckNotificationRequest 在 IsCommonLiveView() 通过后增加 notificationContent_ 和内部 content_ 两层判空,返回 ERR_ANS_INNER_INVALID_PARAM 并记录 bundle/id 日志(与 CheckVersion、GetLiveViewStatus 既有防御模式一致)
  • 新增 8 个单元测试:4 个覆盖两类空指针场景(oldRequest 空与非空)、4 个覆盖 JSON 解析行为与合法 LIVE_VIEW round-trip

兼容性

纯防御性新增,不改变任何合法输入的行为;原本必然崩溃的输入现在返回错误码。

验证

./build.sh --product-name rk3568 --build-target distributed_notification_service
./build.sh --product-name rk3568 --build-target distributed_notification_service_unit_test

构建通过(rk3568 build success,0 编译错误,无新增警告)。

Fixes #4375

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 stepend98 的贡献)
afwk_helper成员
8月25日 评论:

开始进行AI检视!

AI review has been started, please wait...

likedislike
afwk_helper成员
8月25日 评论:
check type result report
start ai_review pass -
likedislike
stepend98stepend98
8月25日 修改了pull request 的描述
stepend98
stepend98
8月25日 评论:

start build

likedislike
openharmony_ciopenharmony_ci成员
8月25日 添加了label:waiting_on_author
此处折叠了63条消息 查看更多
afwk_helper成员
9月2日 评论:

自定义PR管控检查报告 / Custom PR Control Check Report

检查项 检查结果 处理建议
TDD检查 ✓ 通过 -
检视意见 ✓ 通过 -
likedislike
openharmony_ciopenharmony_ci成员
9月2日 关闭了关联的issue
openharmony_ciopenharmony_ci成员
9月2日 合入了pull request,合并节点 SHA:c1b90dd8ac3083c65a74af805eb4c2445afdea55
openharmony_ciopenharmony_ci成员
9月2日 删除了label:waiting_for_review
openharmony_ciopenharmony_ci成员
9月2日 添加了label:merged