fix: 修复 GetNearestZones 空输入越界访问 (DDE-142) - #3444
MyLeeJiEun wants to merge 1 commit into
Conversation
1. Add isEmpty guard at GetNearestZones entry, return empty list early 2. Avoid out-of-bounds total_zones.at(-1) on empty input (UB) 3. Carry ut_timezone_map_util tests from PR linuxdeepin#3421 with empty-input case Log: Prevent datetime timezone-map crash when no zone data is loaded Influence: 1. Test clicking the timezone map with no zone data loaded 2. Verify GetNearestZones returns empty list for empty input 3. Run ut_timezone_map_util unit tests (16 cases) fix: 修复 GetNearestZones 空输入越界访问 1. GetNearestZones 入口增加 total_zones 空输入判空保护,空输入直接返回空列表 2. 避免回退分支 total_zones.at(-1) 对空列表越界访问(未定义行为) 3. 携带 PR linuxdeepin#3421 的 ut_timezone_map_util 测试并补充空输入用例 Log: 避免 zone 数据未加载时点击时区地图导致控制中心崩溃 Influence: 1. 测试未加载 zone 数据时点击时区地图不崩溃 2. 验证 GetNearestZones 空输入返回空列表 3. 运行 ut_timezone_map_util 单元测试(16 个用例)
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: MyLeeJiEun The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAdds an entry-point guard to GetNearestZones so empty total_zones inputs return safely instead of dereferencing at(-1), with regression and broader utility tests wired into the existing unit-test target. Sequence diagram for safe empty-zone lookupsequenceDiagram
participant Test as UnitTest
participant Util as GetNearestZones
participant Zones as total_zones
Test->>Util: GetNearestZones(total_zones, threshold, x, y, map_width, map_height)
Util->>Zones: isEmpty()
alt empty input
Util-->>Test: empty ZoneInfoList
else zones available
Util-->>Test: nearest zones
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Hi @MyLeeJiEun. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
TAG Bot New tag: 6.1.106 |
|
TAG Bot New tag: 6.1.107 |
|
TAG Bot New tag: 6.1.109 |
关联 issue
修复内容
GetNearestZones在total_zones为空时,循环不执行、nearest_zone_index保持初值 -1,回退分支zones.append(total_zones.at(-1))对空QList越界访问(未定义行为),可能导致 datetime 模块地图选时区功能在 zone 数据未加载时崩溃。在函数入口增加
total_zones.isEmpty()判空保护,空输入直接返回空列表:调用方
datetimemodel.cpp无需修改,无接口变更、无跨模块影响。变更文件(仅 3 个)
src/plugin-datetime/operation/timezoneMap/timezone_map_util.cpp—GetNearestZones入口增加空输入判空保护(+3 行)tests/ut_timezone_map_util.cpp(新增)— 从 PR test: 补充控制中心 12 个核心单元的全量单元测试 (DDE-104) #3421 携带,并将原「空输入因 UB 故意省略」的 NOTE 替换为实际的GetNearestZones.EmptyInputReturnsEmptyList空输入测试用例tests/CMakeLists.txt— 注册ut_timezone_map_util.cpp及被测源timezone_map_util.cpp,添加 include 目录(已剥离 gcov 插桩,仅保留最小测试注册)与 PR #3421 的关系
本 PR 的
tests/ut_timezone_map_util.cpp是 #3421 对应文件的超集(新增了GetNearestZones.EmptyInputReturnsEmptyList空输入用例)。rebase #3421 时以本 PR 版本为准;#3421 可视情况关闭。验证
master/307bdbfGetNearestZones.EmptyInputReturnsEmptyList验证:空total_zones输入时函数返回空列表,不再触发total_zones.at(-1)越界访问。Summary by Sourcery
Prevent crashes when timezone map data is unavailable and add regression coverage for timezone map utilities.
Bug Fixes:
Enhancements:
Build:
Tests: