!18484 merge modulemanager_modify into master

fix: blocklist empty when second call

Created-by: yewei0794
Commit-by: yewei0794
Merged-by: openharmony_ci
Description: **IssueNo**:https://gitcode.com/openharmony/ability_ability_runtime/issues/14587

**Description**:

**稳定性自检:**
| 自检项                                                       | 自检结果  |
| ------------------------------------------------------------ | -------- |
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发              |     Y     |
| 成员变量进行赋值或创建需要排查并发                               |      Y    |
| 谨慎在lambda表达式中使用引用捕获                                |    Y      |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串               |     Y     |
| map\vector\list\set等stl模板类使用时需要排查并发                |      Y    |
| 谨慎考虑加锁范围                                               |     Y     |
| 在IPC通信中谨慎使用同步通信方式                                 |    Y      |
| 禁止传递this指针至其他模块或线程(特别是eventhandler任务)        |    Y      |
| 禁止将外部传入的裸指针在内部直接构造智能指针                      |     Y     |
| 禁止多个独立创建的智能指针管理同一地址                           |     Y     |
| 禁止在析构函数中抛异步任务                                      |     Y     |
| 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁             |     Y     |
| 禁止在对外接口中未经判空直接使用外部传入的指针                    |     Y     |
| 禁止接口返回局部变量引用                                        |     Y     |
| 禁止在信号函数中加锁                                            |    Y      |
| 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作           |     Y     |
| 禁止将同一个cpp编译在不同的so中                                 |     Y     |

**安全编码自检:**
| 自检项                                                          | 自检结果 |
| -------------------------------------------------------------- | -------- |
| 裸指针避免通过隐式转换构造为sptr                                 |     Y     |
| json对象在取值之前必须先判断类型,避免类型不匹配                   |    Y      |
| 序列化时必须对传入的数组大小进行校验,避免出现超大数组              |     Y     |
| 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型            |     Y     |
| 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 |      Y    |
| 指针变量、表示资源描述符的变量、bool变量必须赋初值                  |     Y     |
| readParcelable获取的对象使用前需要判空                            |     Y     |
| 分配和释放内存的函数需要成对出现                                   |      Y    |
| 申请内存后异常退出前需要及时进行内存释放                            |     Y     |
| 内存申请前必须对内存大小进行合法性校验                              |     Y     |
| 内存分配后必须判断是否成功                                         |     Y     |
| 禁止使用realloc、alloca函数                                       |     Y     |
| 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰          |     Y     |
| 禁止打印内存地址                                                  |    Y      |
| 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0               |     Y     |
| 禁止对有符号整数进行位操作符运算                                    |     Y     |
| 禁止对指针进行逻辑或位运算                                         |     Y     |
| 循环次数如果收外部数据控制,需要检验其合法性                         |      Y    |
| 禁止使用内存操作类危险函数,需要使用安全函数                         |     Y     |
| 谨慎使用不可重入函数                                               |    Y      |
| 必须检查安全函数的返回值,并进行正确处理                             |     Y     |
| 禁止仅通过TokenType类型判断绕过权限校验                             |     Y     |

**TDD Result**:
![image.png](https://raw.gitcode.com/user-images/assets/4421702/7270ad56-afb4-48cd-a797-89fad6761b43/image.png 'image.png')
**XTS Result**:

### 是否已执行L0用例
- [ ] 已验证
- [ ] 不涉及。如不涉及,请写明理由


See merge request: openharmony/ability_ability_runtime!18484
This commit is contained in:
openharmony_ci
2026-02-28 09:44:37 +08:00
4 changed files with 65 additions and 3 deletions
@@ -31,6 +31,10 @@ namespace {
void ExtensionConfigMgr::LoadExtensionBlockList(const std::string &extensionName, int32_t type)
{
extensionType_ = type;
if (hasUpdatedChecker_) {
TAG_LOGD(AAFwkTag::EXT, "extensionType: %{public}d has updated", extensionType_);
return;
}
{
std::lock_guard<std::mutex> lock(extensionBlockListMutex_);
auto iter = extensionBlocklist_.find(extensionType_);
@@ -95,9 +99,12 @@ void ExtensionConfigMgr::UpdateRuntimeModuleChecker(const std::unique_ptr<Abilit
}
std::unordered_map<int32_t, std::unordered_set<std::string>> localBlocklist;
{
std::lock_guard<std::mutex> lock(extensionBlockListMutex_);
localBlocklist = extensionBlocklist_;
if (!hasUpdatedChecker_) {
{
std::lock_guard<std::mutex> lock(extensionBlockListMutex_);
localBlocklist = extensionBlocklist_;
}
hasUpdatedChecker_ = true;
}
auto moduleChecker = std::make_shared<AppModuleChecker>(extensionType_, localBlocklist);
@@ -97,6 +97,9 @@ private:
/// Current process extension type
int32_t extensionType_ = EXTENSION_TYPE_UNKNOWN;
/// Flag to track if UpdateRuntimeModuleChecker has been called
bool hasUpdatedChecker_ = false;
};
} // namespace OHOS::AbilityRuntime
@@ -18,6 +18,7 @@
#define private public
#define protected public
#include "extension_config_mgr.h"
#include "app_module_checker.h"
#include "mock/mock_runtime.h"
#undef private
#undef protected
@@ -623,5 +624,44 @@ HWTEST_F(ExtensionConfigMgrTest, GetStringAfterRemovePreFix_ShouldReturnOriginal
expectOutput = "@";
EXPECT_EQ(mgr.GetStringAfterRemovePreFix(input), expectOutput);
}
/**
* @tc.name: UpdateRuntimeModuleChecker_ShouldPassEmptyBlocklist_WhenCalledSecondTime
* @tc.desc: func should pass empty localBlocklist to AppModuleChecker when called second time.
* @tc.type: FUNC
*/
HWTEST_F(ExtensionConfigMgrTest, UpdateRuntimeModuleChecker_ShouldPassEmptyBlocklist_WhenCalledSecondTime,
TestSize.Level1)
{
ExtensionConfigMgr mgr;
mgr.LoadExtensionBlockList(BLOCK_LIST_ITEM_FORM_EXTENSION, EXTENSION_TYPE_FORM);
mgr.extensionType_ = EXTENSION_TYPE_FORM;
auto mockRuntimePtr = std::make_unique<MockRuntime>();
mockRuntimePtr->SetLanguage(Runtime::Language::JS);
std::unique_ptr<Runtime> runtime = std::move(mockRuntimePtr);
mgr.UpdateRuntimeModuleChecker(runtime);
MockRuntime &mockRuntime = static_cast<MockRuntime&>(*runtime);
EXPECT_TRUE(mockRuntime.loadCheckerFlag_);
auto firstChecker = mockRuntime.GetModuleChecker();
EXPECT_NE(firstChecker, nullptr);
std::unique_ptr<ApiAllowListChecker> apiAllowListChecker;
bool firstCheckResult = firstChecker->CheckModuleLoadable("multimedia.camera", apiAllowListChecker, false);
EXPECT_FALSE(firstCheckResult);
mockRuntime.ClearModuleChecker();
mgr.UpdateRuntimeModuleChecker(runtime);
auto secondChecker = mockRuntime.GetModuleChecker();
EXPECT_NE(secondChecker, nullptr);
EXPECT_TRUE(mockRuntime.loadCheckerFlag_);
std::unique_ptr<ApiAllowListChecker> apiAllowListChecker2;
bool secondCheckResult = secondChecker->CheckModuleLoadable("multimedia.camera", apiAllowListChecker2, false);
EXPECT_TRUE(secondCheckResult);
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -60,6 +60,7 @@ public:
void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override
{
loadCheckerFlag_ = true;
moduleChecker_ = moduleCheckerDelegate;
}
void SetExtensionApiCheckCallback(
std::function<bool(const std::string &className, const std::string &fileName)> &cb) override
@@ -75,11 +76,22 @@ public:
{
return checkLibraryPermissionCallback_;
}
std::shared_ptr<ModuleCheckerDelegate> GetModuleChecker() const
{
return moduleChecker_;
}
void ClearModuleChecker()
{
moduleChecker_ = nullptr;
}
private:
Runtime::Language language_ = Runtime::Language::ETS;
ExtensionApiCheckCallback checkLibraryPermissionCallback_ {nullptr};
mutable bool loadCheckerFlag_ = false;
bool extensionApiCheckerFlag_ = false;
mutable std::shared_ptr<ModuleCheckerDelegate> moduleChecker_ = nullptr;
};
} // namespace AbilityRuntime
} // namespace OHOS