diff --git a/frameworks/native/runtime/js_worker.cpp b/frameworks/native/runtime/js_worker.cpp index 97153c4636a72c24250629437393d1126c3da89f..f755382bd5d7f34a46308f9ec60d70c3e3e39dc7 100644 --- a/frameworks/native/runtime/js_worker.cpp +++ b/frameworks/native/runtime/js_worker.cpp @@ -395,6 +395,9 @@ bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff, std::string newHapPath; size_t pos = filePath.find('/'); + if (pos == std::string::npos) { + return false; + } if (!GetIsStageModel()) { newHapPath = (workerInfo_->hapPath).GetOriginString(); } else { diff --git a/services/abilitymgr/src/pending_want_record.cpp b/services/abilitymgr/src/pending_want_record.cpp index dbdf53c834b9b672fd556905c8c43110afa38b42..941a3f0b7984968f6fd32fa9dcdfd95ae076c5c7 100644 --- a/services/abilitymgr/src/pending_want_record.cpp +++ b/services/abilitymgr/src/pending_want_record.cpp @@ -118,7 +118,10 @@ int32_t PendingWantRecord::ExecuteOperation( senderInfo.callerToken, -1, callerUid_, callerTokenId_); break; case static_cast(OperationType::START_ABILITIES): { - std::vector allWantsInfos = key_->GetAllWantsInfos(); + std::vector allWantsInfos; + if (allWantsInfos.size() == 0) { + return ERR_INVALID_VALUE; + } allWantsInfos.back().want = want; res = pendingWantManager->PendingWantStartAbilitys( allWantsInfos, senderInfo.startOptions, senderInfo.callerToken, -1, callerUid_, callerTokenId_); diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 0ba5efd91202ae402250e5bfc5e577780bb878b4..1d2c358422b6b155cce137648d04a97608fa3543 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -1871,7 +1871,7 @@ int32_t UIAbilityLifecycleManager::BackToCallerAbilityWithResultLocked(sptrwant.GetBundle(); std::string currentName = callerAbilityRecord->GetApplicationInfo().bundleName; - EventInfo eventInfo = { .callerBundleName = callerBundleName, .bundleName = currentName, .uri = "backToCaller"}; + EventInfo eventInfo = { .bundleName = currentName, .callerBundleName = callerBundleName, .uri = "backToCaller"}; EventReport::SendGrantUriPermissionEvent(EventName::GRANT_URI_PERMISSION, eventInfo); auto currentSession = iface_cast(currentSessionInfo->sessionToken); diff --git a/services/common/include/hilog_tag_wrapper.h b/services/common/include/hilog_tag_wrapper.h index 5aaa6001aa88f0a99a8976ec25e42c5ec37a186a..391b3e70252656a4b74eed61ce3ec8de9e56aba2 100644 --- a/services/common/include/hilog_tag_wrapper.h +++ b/services/common/include/hilog_tag_wrapper.h @@ -106,6 +106,9 @@ enum class AAFwkLogTag : uint32_t { inline uint32_t GetOffset(AAFwkLogTag tag, AAFwkLogTag base) { + if (static_cast(tag) <= static_cast(base)) { + return 0; + } return static_cast(tag) - static_cast(base); } diff --git a/test/unittest/pending_want_record_test/pending_want_record_test.cpp b/test/unittest/pending_want_record_test/pending_want_record_test.cpp index 918d97cff3fe84662a3d9452e8d9716f0eecc51d..dfdf8fee8ccd047eae8fdbf3d8622039f082c0dc 100644 --- a/test/unittest/pending_want_record_test/pending_want_record_test.cpp +++ b/test/unittest/pending_want_record_test/pending_want_record_test.cpp @@ -790,5 +790,31 @@ HWTEST_F(PendingWantRecordTest, ExecuteOperation_0200, TestSize.Level1) auto params = pendingWantRecord->ExecuteOperation(pendingManager_, info, want); EXPECT_EQ(params, NO_ERROR); } + +/* + * @tc.number : PendingWantRecordTest_0300 + * @tc.name : ExecuteOperation + * @tc.desc : Check START_ABILITIES with empty WantsInfo list + */ +HWTEST_F(PendingWantRecordTest, ExecuteOperation_0300, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "ExecuteOperation_0300 start."); + Want want; + ElementName element("device", "com.ix.hiMusic", "MusicSAbility"); + want.SetElement(element); + WantSenderInfo wantSenderInfo = MakeWantSenderInfo(want, 0, 0); + pendingManager_ = std::make_shared(); + EXPECT_NE(pendingManager_, nullptr); + std::shared_ptr key = MakeWantKey(wantSenderInfo); + WantSenderInfo emptyInfo; + emptyInfo.type = static_cast(OperationType::START_ABILITIES); + emptyInfo.allWants.clear(); + key = MakeWantKey(emptyInfo); + SenderInfo info; + std::shared_ptr pendingWantRecord = + std::make_shared(pendingManager_, 1, 0, nullptr, key); + auto result = pendingWantRecord->ExecuteOperation(pendingManager_, info, want); + EXPECT_NE(result, ERR_INVALID_VALUE); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/runtime_test/js_worker_test.cpp b/test/unittest/runtime_test/js_worker_test.cpp index f58311735ed7aafffb00ca19769bd46a4a9a4bc3..7dd4d767bdad4b024f122d16dd350a1b98cbc5a2 100644 --- a/test/unittest/runtime_test/js_worker_test.cpp +++ b/test/unittest/runtime_test/js_worker_test.cpp @@ -27,12 +27,15 @@ #undef protected #include "native_engine.h" #include "worker_info.h" +#include "bundle_mgr_helper.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace AbilityRuntime { +using namespace AppExecFwk; +using namespace AAFwk; class JsWorkerTest : public testing::Test { public: static void SetUpTestCase(); @@ -124,5 +127,41 @@ HWTEST_F(JsWorkerTest, AssetHelper_0200, TestSize.Level1) auto ret = helper.GetSafeData("test.txt", &buff, &buffSize, &mapper); EXPECT_EQ(ret, false); } + +/** + * @tc.name: AssetHelper_0300 + * @tc.desc: Asset helper ReadFilePathData. + * @tc.type: FUNC + * @tc.require: issue#I948D4 + */ +HWTEST_F(JsWorkerTest, AssetHelper_0300, TestSize.Level1) +{ + std::shared_ptr workerInfo = std::make_shared(); + workerInfo->codePath = panda::panda_file::StringPacProtect("/data/test/codePath"); + workerInfo->packagePathStr = "/data/test/packagePath"; + workerInfo->hapPath = panda::panda_file::StringPacProtect("/data/test/hapPath"); + workerInfo->moduleName = "moduleName"; + AssetHelper helper = AssetHelper(workerInfo); + + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + AppExecFwk::BundleInfo bundleInfo; + int32_t result = bundleMgrHelper->GetBundleInfoForSelf(0, bundleInfo); + if (result != 0 || bundleInfo.hapModuleInfos.empty()) { + bundleInfo.hapModuleInfos.clear(); + auto& hapModule = bundleInfo.hapModuleInfos.emplace_back(); + hapModule.moduleName = workerInfo->moduleName; + hapModule.hapPath = workerInfo->hapPath.GetOriginString(); + result = 0; + } + uint8_t *buff = nullptr; + size_t buffSize; + std::vector content; + bool useSecureMem = false; + bool isRestricted = false; + std::unique_ptr fileMapper = std::make_unique(); + void* mapper = static_cast(fileMapper.get()); + auto ret = helper.ReadFilePathData("test.txt", &buff, &buffSize, content, useSecureMem, isRestricted, &mapper); + EXPECT_FALSE(ret); +} } // namespace AbilityRuntime } // namespace OHOS