From 98323a98804b3955d2e2fe043d8b235c5314a82f Mon Sep 17 00:00:00 2001 From: zoulianfeng Date: Wed, 11 Oct 2023 11:31:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9entInfo=20=E4=B8=8E=20Edm?= =?UTF-8?q?Permission=E7=9A=84=E5=BA=8F=E5=88=97=E5=8C=96=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E4=B8=8D=E5=86=8D=E8=BF=94=E5=9B=9E=E6=8C=87?= =?UTF-8?q?=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zoulianfeng --- common/native/include/edm_permission.h | 2 +- common/native/src/edm_permission.cpp | 6 ++---- interfaces/inner_api/common/include/ent_info.h | 2 +- interfaces/inner_api/common/src/ent_info.cpp | 10 ++-------- .../common/src/enterprise_device_mgr_proxy.cpp | 4 +--- services/edm/src/enterprise_device_mgr_stub.cpp | 12 ++++++------ test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp | 3 +-- test/unittest/src/edm_permission_test.cpp | 9 +++------ test/unittest/src/ent_info_test.cpp | 16 +++++----------- 9 files changed, 22 insertions(+), 42 deletions(-) diff --git a/common/native/include/edm_permission.h b/common/native/include/edm_permission.h index 910890730..2c1571911 100644 --- a/common/native/include/edm_permission.h +++ b/common/native/include/edm_permission.h @@ -34,7 +34,7 @@ public: virtual bool Marshalling(Parcel &parcel) const override; - static EdmPermission *Unmarshalling(Parcel &parcel); + static bool Unmarshalling(Parcel &parcel, EdmPermission &edmPermission); const std::string &getPermissionName() const; diff --git a/common/native/src/edm_permission.cpp b/common/native/src/edm_permission.cpp index 701e55d87..e5aadbd7d 100644 --- a/common/native/src/edm_permission.cpp +++ b/common/native/src/edm_permission.cpp @@ -68,11 +68,9 @@ bool EdmPermission::Marshalling(Parcel &parcel) const return true; } -EdmPermission *EdmPermission::Unmarshalling(Parcel &parcel) +bool EdmPermission::Unmarshalling(Parcel &parcel, EdmPermission &edmPermission) { - auto *permission = new (std::nothrow)EdmPermission(); - permission->ReadFromParcel(parcel); - return permission; + return edmPermission.ReadFromParcel(parcel); } } // namespace EDM } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/common/include/ent_info.h b/interfaces/inner_api/common/include/ent_info.h index a3d553569..59a58abc7 100644 --- a/interfaces/inner_api/common/include/ent_info.h +++ b/interfaces/inner_api/common/include/ent_info.h @@ -30,7 +30,7 @@ struct EntInfo : public Parcelable { std::string description; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; - static EntInfo *Unmarshalling(Parcel &parcel); + static bool Unmarshalling(Parcel &parcel, EntInfo &entInfo); }; } // namespace EDM } // namespace OHOS diff --git a/interfaces/inner_api/common/src/ent_info.cpp b/interfaces/inner_api/common/src/ent_info.cpp index a07a1d854..b1b1e3e69 100644 --- a/interfaces/inner_api/common/src/ent_info.cpp +++ b/interfaces/inner_api/common/src/ent_info.cpp @@ -43,15 +43,9 @@ bool EntInfo::Marshalling(Parcel &parcel) const return true; } -EntInfo *EntInfo::Unmarshalling(Parcel &parcel) +bool EntInfo::Unmarshalling(Parcel &parcel, EntInfo &entInfo) { - auto *info = new (std::nothrow) EntInfo(); - if (info && !info->ReadFromParcel(parcel)) { - EDMLOGW("read from parcel failed"); - delete info; - info = nullptr; - } - return info; + return entInfo.ReadFromParcel(parcel); } bool EntInfo::ReadFromParcel(Parcel &parcel) diff --git a/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp b/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp index 45cd23da9..76ca21f44 100644 --- a/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp +++ b/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp @@ -202,12 +202,10 @@ ErrCode EnterpriseDeviceMgrProxy::GetEnterpriseInfo(AppExecFwk::ElementName &adm EDMLOGW("EnterpriseDeviceMgrProxy:GetEnterpriseInfo get result code fail. %{public}d", resCode); return resCode; } - std::unique_ptr info(reply.ReadParcelable()); - if (!info) { + if (!EntInfo::Unmarshalling(reply, entInfo)) { EDMLOGE("EnterpriseDeviceMgrProxy::GetEnterpriseInfo read parcel fail"); return EdmReturnErrCode::SYSTEM_ABNORMALLY; } - entInfo = *info; return ERR_OK; } diff --git a/services/edm/src/enterprise_device_mgr_stub.cpp b/services/edm/src/enterprise_device_mgr_stub.cpp index 153025c9e..7130d2632 100644 --- a/services/edm/src/enterprise_device_mgr_stub.cpp +++ b/services/edm/src/enterprise_device_mgr_stub.cpp @@ -112,8 +112,8 @@ ErrCode EnterpriseDeviceMgrStub::EnableAdminInner(MessageParcel &data, MessagePa } EDMLOGD("EnableAdminInner bundleName:: %{public}s : abilityName : %{public}s ", admin->GetBundleName().c_str(), admin->GetAbilityName().c_str()); - std::unique_ptr entInfo(data.ReadParcelable()); - if (!entInfo) { + EntInfo entInfo; + if (!EntInfo::Unmarshalling(data, entInfo)) { EDMLOGE("EnterpriseDeviceMgrStub::EnableAdminInner read parcel fail"); reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR); return EdmReturnErrCode::PARAM_ERROR; @@ -124,7 +124,7 @@ ErrCode EnterpriseDeviceMgrStub::EnableAdminInner(MessageParcel &data, MessagePa if (type == static_cast(AdminType::NORMAL) || type == static_cast(AdminType::ENT)) { adminType = static_cast(type); } - ErrCode retCode = EnableAdmin(*admin, *entInfo, adminType, userId); + ErrCode retCode = EnableAdmin(*admin, entInfo, adminType, userId); reply.WriteInt32(retCode); return ERR_OK; } @@ -241,12 +241,12 @@ ErrCode EnterpriseDeviceMgrStub::SetEnterpriseInfoInner(MessageParcel &data, Mes reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR); return EdmReturnErrCode::PARAM_ERROR; } - std::unique_ptr entInfo(data.ReadParcelable()); - if (!entInfo) { + EntInfo entInfo; + if (!EntInfo::Unmarshalling(data, entInfo)) { reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR); return EdmReturnErrCode::PARAM_ERROR; } - ErrCode ret = SetEnterpriseInfo(*admin, *entInfo); + ErrCode ret = SetEnterpriseInfo(*admin, entInfo); reply.WriteInt32(ret); return ERR_OK; } diff --git a/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp b/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp index b1ce9b79b..e26bbd6b2 100644 --- a/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp +++ b/test/fuzztest/entinfo_fuzzer/entinfo_fuzzer.cpp @@ -28,8 +28,7 @@ namespace OHOS { EntInfo entInfo; std::string entName(reinterpret_cast(data), size); entInfo.enterpriseName = entName; - std::unique_ptr entInfoPtr(EntInfo::Unmarshalling(dataMessageParcel)); - return entInfoPtr != nullptr; + return EntInfo::Unmarshalling(dataMessageParcel, entInfo); } } diff --git a/test/unittest/src/edm_permission_test.cpp b/test/unittest/src/edm_permission_test.cpp index 4cc873e30..01ec6c213 100644 --- a/test/unittest/src/edm_permission_test.cpp +++ b/test/unittest/src/edm_permission_test.cpp @@ -60,12 +60,9 @@ HWTEST_F(EdmPermissionTest, TestMarshalling, TestSize.Level1) EdmPermission permission1("ohos.permission.EDM_TEST_PERMISSION", AdminType::NORMAL); Parcel parcel; permission1.Marshalling(parcel); - EdmPermission *permission2 = permission1.Unmarshalling(parcel); - EXPECT_TRUE(permission2 != nullptr); - EXPECT_TRUE(permission1 == *permission2); - if (permission2) { - delete permission2; - } + EdmPermission permission2; + EXPECT_TRUE(EdmPermission::Unmarshalling(parcel, permission2)); + EXPECT_TRUE(permission1 == permission2); } } // namespace TEST } // namespace EDM diff --git a/test/unittest/src/ent_info_test.cpp b/test/unittest/src/ent_info_test.cpp index 39112e24f..f560a6db7 100644 --- a/test/unittest/src/ent_info_test.cpp +++ b/test/unittest/src/ent_info_test.cpp @@ -58,18 +58,12 @@ HWTEST_F(EntInfoTest, TestMarshalling, TestSize.Level1) EXPECT_TRUE(ret); EntInfo entinfo; - EntInfo *entinfo1 = entinfo.Unmarshalling(parcel); - EXPECT_TRUE(entinfo1 != nullptr); + EXPECT_TRUE(EntInfo::Unmarshalling(parcel, entinfo)); - EXPECT_STREQ((entinfo1->enterpriseName).c_str(), NAME.c_str()); - EXPECT_STREQ((entinfo1->description).c_str(), DESCRIPTION.c_str()); - EXPECT_STREQ((entInfoTest->enterpriseName).c_str(), (entinfo1->enterpriseName).c_str()); - EXPECT_STREQ((entInfoTest->description).c_str(), (entinfo1->description).c_str()); - - if (entinfo1) { - delete entinfo1; - entinfo1 = nullptr; - } + EXPECT_STREQ(entinfo.enterpriseName.c_str(), NAME.c_str()); + EXPECT_STREQ(entinfo.description.c_str(), DESCRIPTION.c_str()); + EXPECT_STREQ((entInfoTest->enterpriseName).c_str(), entinfo.enterpriseName.c_str()); + EXPECT_STREQ((entInfoTest->description).c_str(), entinfo.description.c_str()); } } // namespace TEST } // namespace EDM -- Gitee From 9abb4fb399c66f745c0d98d4cf8940db6059e92e Mon Sep 17 00:00:00 2001 From: zoulianfeng Date: Wed, 11 Oct 2023 16:38:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9ut=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zoulianfeng --- test/unittest/test_bundle/ohos_test/BUILD.gn | 2 +- test/unittest/test_bundle/right_hap/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/test_bundle/ohos_test/BUILD.gn b/test/unittest/test_bundle/ohos_test/BUILD.gn index 572c0cd58..15bc3e347 100644 --- a/test/unittest/test_bundle/ohos_test/BUILD.gn +++ b/test/unittest/test_bundle/ohos_test/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") ohos_copy("copy_ohos_test") { sources = [ "./ohos_test.xml" ] - outputs = [ "$root_out_dir/tests/unittest/enterprise_device_management/services/resource/ohos_test.xml" ] + outputs = [ "$root_out_dir/tests/unittest/enterprise_device_management/enterprise_device_management/resource/ohos_test.xml" ] subsystem_name = "customization" part_name = "enterprise_device_management" } diff --git a/test/unittest/test_bundle/right_hap/BUILD.gn b/test/unittest/test_bundle/right_hap/BUILD.gn index b0cf8c323..bef1bb33f 100644 --- a/test/unittest/test_bundle/right_hap/BUILD.gn +++ b/test/unittest/test_bundle/right_hap/BUILD.gn @@ -18,7 +18,7 @@ ohos_hap("right") { hap_name = "right" subsystem_name = "customization" part_name = "enterprise_device_management" - final_hap_path = "$root_out_dir/tests/unittest/enterprise_device_management/services/resource/test_bundle/${hap_name}.hap" + final_hap_path = "$root_out_dir/tests/unittest/enterprise_device_management/enterprise_device_management/resource/test_bundle/${hap_name}.hap" testonly = true deps = [ ":hjs_demo_js_assets", -- Gitee