Skip to content

[Autofix][high] Alert #68: Incorrect allocation-error handling - #81

Merged
xengine-qyt merged 1 commit into
developfrom
autofix/high/alert-68
Jun 24, 2026
Merged

[Autofix][high] Alert #68: Incorrect allocation-error handling#81
xengine-qyt merged 1 commit into
developfrom
autofix/high/alert-68

Conversation

@xengine-qyt

Copy link
Copy Markdown
Collaborator

🤖 Copilot Autofix 自动修复报告


📋 基本信息

字段内容
Alert ID#68
安全级别high
规则名称Incorrect allocation-error handling
问题文件XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.cpp 第 57 行
CWE 分类external/cwe/cwe-252, external/cwe/cwe-570, external/cwe/cwe-755
规则标签correctness, external/cwe/cwe-252, external/cwe/cwe-570, external/cwe/cwe-755, security

🔍 问题说明

Incorrect allocation-error handling

Different overloads of the new operator handle allocation failures in different ways. If new T fails for some type T, it throws a std::bad_alloc exception, but new(std::nothrow) T returns a null pointer. If the programmer does not use the corresponding method of error handling, allocation failure may go unhandled and could cause the program to behave in unexpected ways.

Recommendation

Make sure that exceptions are handled appropriately if new T is used. On the other hand, make sure to handle the possibility of null pointers if new(std::nothrow) T is used.

Example

// BAD: the allocation will throw an unhandled exception// instead of returning a null pointer.voidbad1(std::size_t length) noexcept {
int* dest = newint[l
---
### 🤖 AI 修复思路
Use allocation semantics that match the existing error-handling path. Since the current function already expects allocation failure to be represented as `NULL` and then sets module-specific error codes, the least invasive fix is to change the allocation to `new (std::nothrow) BTORRENT_DLOADINFO;` and keep the existing null check.
Best single fix in this file/region:
- In `XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.cpp`, inside `CBTorrent_DLoader::BTorrent_DLoader_Create(...)`, replace line 57 allocation with `new (std::nothrow)`.
- Add `#include <new>` near the includes so `std::nothrow` is available.
This preserves existing behavior, avoids introducing exception handling changes, and makes line 58’s null check correct.
---
### ✅ Review 检查清单
- [ ] 理解了漏洞的成因和影响范围
- [ ] 确认 AI 修复逻辑正确,没有遗漏边界情况
- [ ] 确认修复没有改变原有业务逻辑
- [ ] 确认没有引入新的安全问题
- [ ] CI / 单元测试全部通过
- [ ] 如有必要,已补充对应的测试用例
---
> 此 PR 由 GitHub Copilot Autofix 自动生成,请仔细审核后再 merge。

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@xengine-qyt
xengine-qyt marked this pull request as ready for review June 24, 2026 08:41
@xengine-qyt
xengine-qyt merged commit 636a01d into developJun 24, 2026
@xengine-qyt
xengine-qyt deleted the autofix/high/alert-68 branch June 24, 2026 08:42
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@xengine-qyt