已合并
修复查询子进程相关错误码转化问题 #20310
SKY2001创建于 8月27日
修复查询子进程相关错误码转化问题 #20310
已合并
共 6 个文件变更+8-8
| @@ -342,7 +342,7 @@ private: | |||
| 342 | if (!innerErrorCode || !childInfos) { | 342 | if (!innerErrorCode || !childInfos) { |
| 343 | TAG_LOGE(AAFwkTag::PROCESSMGR, "null innerErrorCode or childInfos"); | 343 | TAG_LOGE(AAFwkTag::PROCESSMGR, "null innerErrorCode or childInfos"); |
| 344 | task.Reject(env, CreateJsError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), | 344 | task.Reject(env, CreateJsError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), |
| 345 | - GetInnerErrorMsg(AbilityInnerErrorMsg::GET_PROCESS_INFO_FAILED))); | 345 | + GetErrorMsg(AbilityErrorCode::ERROR_CODE_INNER))); |
| 346 | return; | 346 | return; |
| 347 | } | 347 | } |
| 348 | if (*innerErrorCode == ChildProcessManagerErrorCode::ERR_OK) { | 348 | if (*innerErrorCode == ChildProcessManagerErrorCode::ERR_OK) { |
| @@ -675,7 +675,7 @@ ChildProcessManagerErrorCode ChildProcessManager::AcquireChildProcesses( | |||
| 675 | auto ret = client->GetSelfChildrenProcesses(infos); | 675 | auto ret = client->GetSelfChildrenProcesses(infos); |
| 676 | if (ret != AppExecFwk::AppMgrResultCode::RESULT_OK) { | 676 | if (ret != AppExecFwk::AppMgrResultCode::RESULT_OK) { |
| 677 | TAG_LOGE(AAFwkTag::PROCESSMGR, "GetSelfChildrenProcesses failed, ret=%{public}d", ret); | 677 | TAG_LOGE(AAFwkTag::PROCESSMGR, "GetSelfChildrenProcesses failed, ret=%{public}d", ret); |
| 678 | - return ChildProcessManagerErrorCode::ERR_APP_MGR_FAILED_INNER; | 678 | + return ChildProcessManagerErrorUtil::GetChildProcessManagerErrorCode(ret); |
| 679 | } | 679 | } |
| 680 | return ChildProcessManagerErrorCode::ERR_OK; | 680 | return ChildProcessManagerErrorCode::ERR_OK; |
| 681 | } | 681 | } |
| @@ -1130,7 +1130,7 @@ int32_t ApplicationContext::GetProcessRunningInformation(AppExecFwk::RunningProc | |||
| 1130 | 1130 | ||
| 1131 | int32_t ApplicationContext::GetUIAbilityChildProcessInfos(std::vector<AppExecFwk::ChildProcessInfo> &infos) | 1131 | int32_t ApplicationContext::GetUIAbilityChildProcessInfos(std::vector<AppExecFwk::ChildProcessInfo> &infos) |
| 1132 | { | 1132 | { |
| 1133 | - return (contextImpl_ != nullptr) ? contextImpl_->GetUIAbilityChildProcessInfos(infos) : -1; | 1133 | + return (contextImpl_ != nullptr) ? contextImpl_->GetUIAbilityChildProcessInfos(infos) : ERR_INVALID_VALUE; |
| 1134 | } | 1134 | } |
| 1135 | 1135 | ||
| 1136 | 1136 | ||
| @@ -129,9 +129,8 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ChildProcessInfo_GetProcessName( | |||
| 129 | return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; | 129 | return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; |
| 130 | } | 130 | } |
| 131 | if (info->processName == nullptr) { | 131 | if (info->processName == nullptr) { |
| 132 | - *requiredSize = 1; | 132 | + *requiredSize = 0; |
| 133 | - processName[0] = '\0'; | 133 | + return ABILITY_RUNTIME_ERROR_CODE_INTERNAL; |
| 134 | - return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 135 | } | 134 | } |
| 136 | uint32_t nameLen = static_cast<uint32_t>(strlen(info->processName)); | 135 | uint32_t nameLen = static_cast<uint32_t>(strlen(info->processName)); |
| 137 | *requiredSize = nameLen + 1; | 136 | *requiredSize = nameLen + 1; |
| @@ -142,8 +141,7 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ChildProcessInfo_GetProcessName( | |||
| 142 | errno_t rc = strncpy_s(processName, processNameSize, info->processName, nameLen); | 141 | errno_t rc = strncpy_s(processName, processNameSize, info->processName, nameLen); |
| 143 | if (rc != EOK) { | 142 | if (rc != EOK) { |
| 144 | TAG_LOGE(AAFwkTag::PROCESSMGR, "strncpy_s failed, rc=%{public}d", rc); | 143 | TAG_LOGE(AAFwkTag::PROCESSMGR, "strncpy_s failed, rc=%{public}d", rc); |
| 145 | - processName[0] = '\0'; | 144 | + return ABILITY_RUNTIME_ERROR_CODE_INTERNAL; |
A | |||
| 146 | - return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID; | ||
| 147 | } | 145 | } |
| 148 | return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | 146 | return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; |
| 149 | } | 147 | } |
| @@ -112,6 +112,7 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ChildProcessInfo_GetParentPid( | |||
| 112 | * <li>{@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if processName or requiredSize is NULL, | 112 | * <li>{@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if processName or requiredSize is NULL, |
| 113 | * or processNameSize is 0.</li> | 113 | * or processNameSize is 0.</li> |
| 114 | * <li>{@link ABILITY_RUNTIME_ERROR_CODE_BUFFER_TOO_SMALL} if the buffer is too small.</li> | 114 | * <li>{@link ABILITY_RUNTIME_ERROR_CODE_BUFFER_TOO_SMALL} if the buffer is too small.</li> |
| 115 | + * <li>{@link ABILITY_RUNTIME_ERROR_CODE_INTERNAL} if string copy operation failed.</li> | ||
| 115 | * </ul> | 116 | * </ul> |
| 116 | * @since 26.1.0 | 117 | * @since 26.1.0 |
| 117 | */ | 118 | */ |
| @@ -4362,6 +4362,7 @@ int AppMgrServiceInner::GetAllChildrenProcesses(std::vector<ChildProcessInfo> &i | |||
| 4362 | 4362 | ||
| 4363 | int AppMgrServiceInner::GetSelfChildrenProcesses(std::vector<ChildProcessInfo> &info) | 4363 | int AppMgrServiceInner::GetSelfChildrenProcesses(std::vector<ChildProcessInfo> &info) |
| 4364 | { | 4364 | { |
| 4365 | + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); | ||
| 4365 | auto callingTokenId = IPCSkeleton::GetCallingTokenID(); | 4366 | auto callingTokenId = IPCSkeleton::GetCallingTokenID(); |
| 4366 | for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { | 4367 | for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { |
| 4367 | const auto &appRecord = item.second; | 4368 | const auto &appRecord = item.second; |
🤖 AI 代码检视意见(回复本评论可解决检视意见,点击被检视代码行左侧的小头像可收起检视意见)
🟡 strncpy_s 失败时返回内部错误码掩盖了参数错误
位置:
L144| 严重程度: Medium❓ 问题描述
当 strncpy_s 失败时(通常由于传入的 processNameSize 缓冲区过小),代码现在返回 ABILITY_RUNTIME_ERROR_CODE_INTERNAL。这会误导调用者认为系统发生了内部错误,而实际上这通常是调用者提供的缓冲区参数不合法导致的,应返回参数错误码(如 ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID)或专门的缓冲区不足错误码。
💡 修复建议
修改建议:保留参数错误码 ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID,或者使用更具体的缓冲区大小不足错误码,以便调用者正确处理。
144: return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;