!19500 merge carclone into master

Add index check error

Created-by: zivzhen
Commit-by: wangzhen
Merged-by: openharmony_ci
Description: **IssueNo**:

**Description**:

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

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

**TDD Result**:
pass
**XTS Result**:
pass

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


See merge request: openharmony/ability_ability_runtime!19500
This commit is contained in:
openharmony_ci
2026-06-01 16:41:17 +08:00
4 changed files with 57 additions and 30 deletions
@@ -26,7 +26,7 @@ namespace OHOS {
namespace AAFwk {
class CloneForAccountUtil {
public:
static void ProcessAppIndex(Want &want, int32_t userId);
static bool ProcessAppIndex(Want &want, int32_t userId);
};
} // namespace AAFwk
} // namespace OHOS
@@ -699,7 +699,8 @@ int AbilityManagerService::StartAbility(const Want &want, int32_t userId, int re
userId = GetValidUserId(userId);
}
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), userId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), userId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
XCOLLIE_TIMER_LESS_IGNORE(__PRETTY_FUNCTION__, !want.GetDeviceId().empty());
@@ -1392,7 +1393,8 @@ int AbilityManagerService::StartAbilityInner(StartAbilityWrapParam &param)
}
int32_t oriValidUserId = GetValidUserId(param.userId);
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(param.want, oriValidUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(param.want, oriValidUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
std::string dialogSessionId = param.want.GetStringParam("dialogSessionId");
bool isSendDialogResult = false;
@@ -1838,7 +1840,8 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt
EventInfo eventInfo = BuildEventInfo(want, userId);
int32_t oriValidUserId = GetValidUserId(userId);
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
if (want.GetBoolParam(AbilityConfig::DEBUG_APP, false)) {
if (!system::GetBoolParameter(DEVELOPER_MODE_STATE, false)) {
@@ -2219,7 +2222,8 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St
EventInfo eventInfo = BuildEventInfo(want, userId);
int32_t oriValidUserId = GetValidUserId(userId);
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
// prevent the app from dominating the screen
if (callerToken == nullptr && !IsCallerSceneBoard() && !isCallByShortcut &&
@@ -2629,7 +2633,8 @@ int32_t AbilityManagerService::StartUIAbilitiesInSplitWindowModeHandleWant(const
int32_t requestCode = DEFAULT_INVAL_VALUE;
int32_t appIndex = 0;
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(secondaryWant), validUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(secondaryWant), validUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
AbilityUtil::RemoveShowModeKey(const_cast<Want &>(secondaryWant));
auto result = CheckWantForSplitMode(secondaryWant, callerToken, validUserId, appIndex);
@@ -2781,7 +2786,8 @@ int32_t AbilityManagerService::StartUIAbilitiesHandleWant(const Want &want, sptr
uint32_t specifyTokenId = 0;
int32_t requestCode = DEFAULT_INVAL_VALUE;
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), validUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), validUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
AbilityUtil::RemoveShowModeKey(const_cast<Want &>(want));
@@ -3126,7 +3132,8 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo, Ab
#ifdef ENABLE_CLONE_FOR_ACCOUNT
if (sessionInfo->want.GetBoolParam(ServerConstant::IS_CALL_BY_SCB, true)) {
auto currentUserId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE;
CloneForAccountUtil::ProcessAppIndex(sessionInfo->want, currentUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(sessionInfo->want, currentUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
}
#endif
sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::PAGE_CONFIG, params.pageConfig);
@@ -9950,7 +9957,8 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const
}
int32_t oriValidUserId = GetValidUserId(accountId);
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
AbilityUtil::RemoveWantKey(const_cast<Want &>(want));
int32_t appIndex = 0;
@@ -10074,7 +10082,8 @@ int AbilityManagerService::StartAbilityForPrelaunch(const Want &want, const int3
}
int32_t oriValidUserId = GetValidUserId(DEFAULT_INVAL_VALUE);
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId);
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), oriValidUserId),
RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); };
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, oriValidUserId, true, nullptr,
@@ -11216,7 +11225,8 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr<IRemoteObj
int32_t userId = INVALID_USER_ID;
auto ret = ParseAndValidateUserId(want, userId);
#ifdef ENABLE_CLONE_FOR_ACCOUNT
CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want), GetValidUserId(DEFAULT_INVAL_VALUE));
CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast<Want &>(want),
GetValidUserId(DEFAULT_INVAL_VALUE)), RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed");
#endif
int32_t appIndex = 0;
if (!StartAbilityUtils::GetAppIndex(want, nullptr, appIndex) || appIndex != 0) {
@@ -21,23 +21,29 @@
namespace OHOS {
namespace AAFwk {
void CloneForAccountUtil::ProcessAppIndex(Want &want, int32_t userId)
bool CloneForAccountUtil::ProcessAppIndex(Want &want, int32_t userId)
{
want.RemoveParam(Want::PARAM_APP_CLONE_INDEX_KEY);
if (want.GetElement().GetAbilityName().empty()) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "implicit start, skip");
return true;
}
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
if (bundleMgrHelper == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleMgrHelper is nullptr");
return;
return false;
}
AppExecFwk::AbilityInfo abilityInfo;
if (!IN_PROCESS_CALL(bundleMgrHelper->QueryEnabledAbilityInfo(want, userId, abilityInfo))) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "QueryEnabledAbilityInfo failed");
return;
return false;
}
want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, abilityInfo.appIndex);
TAG_LOGI(AAFwkTag::ABILITYMGR, "CloneForAccount resolved appIndex: %{public}d", abilityInfo.appIndex);
return true;
}
} // namespace AAFwk
} // namespace OHOS
@@ -46,7 +46,7 @@ void CloneForAccountUtilTest::TearDown() {}
/**
* @tc.name: ProcessAppIndex_001
* @tc.desc: Test ProcessAppIndex success with appIndex in want
* @tc.desc: Test ProcessAppIndex returns true on success with appIndex in want
* @tc.type: FUNC
*/
HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_001, TestSize.Level1)
@@ -61,15 +61,14 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_001, TestSize.Level1)
AppExecFwk::BundleMgrHelper::abilityInfoResult = mockAbilityInfo;
AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = true;
CloneForAccountUtil::ProcessAppIndex(want, 100);
EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_TRUE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
EXPECT_EQ(want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, -1), 1);
}
/**
* @tc.name: ProcessAppIndex_002
* @tc.desc: Test ProcessAppIndex with bundleMgrHelper null
* @tc.desc: Test ProcessAppIndex returns false when bundleMgrHelper is null
* @tc.type: FUNC
*/
HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_002, TestSize.Level1)
@@ -80,14 +79,13 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_002, TestSize.Level1)
want.SetElementName("com.test.bundle", "MainAbility");
want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 1);
CloneForAccountUtil::ProcessAppIndex(want, 100);
EXPECT_FALSE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
}
/**
* @tc.name: ProcessAppIndex_003
* @tc.desc: Test ProcessAppIndex with QueryEnabledAbilityInfo failed
* @tc.desc: Test ProcessAppIndex returns false when QueryEnabledAbilityInfo fails
* @tc.type: FUNC
*/
HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_003, TestSize.Level1)
@@ -98,14 +96,13 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_003, TestSize.Level1)
want.SetElementName("com.test.bundle", "MainAbility");
want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 1);
CloneForAccountUtil::ProcessAppIndex(want, 100);
EXPECT_FALSE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
}
/**
* @tc.name: ProcessAppIndex_004
* @tc.desc: Test ProcessAppIndex with no appIndex in want
* @tc.desc: Test ProcessAppIndex returns true with no appIndex in want
* @tc.type: FUNC
*/
HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_004, TestSize.Level1)
@@ -119,8 +116,7 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_004, TestSize.Level1)
AppExecFwk::BundleMgrHelper::abilityInfoResult = mockAbilityInfo;
AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = true;
CloneForAccountUtil::ProcessAppIndex(want, 100);
EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_TRUE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
EXPECT_EQ(want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, -1), 0);
}
@@ -142,15 +138,14 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_005, TestSize.Level1)
AppExecFwk::BundleMgrHelper::abilityInfoResult = mockAbilityInfo;
AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = true;
CloneForAccountUtil::ProcessAppIndex(want, 100);
EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_TRUE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
EXPECT_EQ(want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, -1), 2);
}
/**
* @tc.name: ProcessAppIndex_006
* @tc.desc: Test ProcessAppIndex removes appIndex before query, query fails
* @tc.desc: Test ProcessAppIndex returns false and removes appIndex when query fails
* @tc.type: FUNC
*/
HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_006, TestSize.Level1)
@@ -161,8 +156,24 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_006, TestSize.Level1)
want.SetElementName("com.test.bundle", "MainAbility");
want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 99);
CloneForAccountUtil::ProcessAppIndex(want, 100);
EXPECT_FALSE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
}
/**
* @tc.name: ProcessAppIndex_007
* @tc.desc: Test ProcessAppIndex returns true on implicit start without query
* @tc.type: FUNC
*/
HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_007, TestSize.Level1)
{
Want want;
want.SetAction("ohos.want.action.viewData");
want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 1);
AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = false;
EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100));
EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY));
}