diff --git a/test/fuzztest/security_component/common/fuzz_common.cpp b/test/fuzztest/security_component/common/fuzz_common.cpp index b3786a14a690bb5afd93fc71fabeb20634008e15..52ac3b2d051a7d1b281224972e2dd34d4fbac76f 100644 --- a/test/fuzztest/security_component/common/fuzz_common.cpp +++ b/test/fuzztest/security_component/common/fuzz_common.cpp @@ -42,6 +42,15 @@ uint32_t CompoRandomGenerator::GetScType() return GetData() % (SecCompType::MAX_SC_TYPE - 1) + 1; } +std::string CompoRandomGenerator::GetMessage() +{ + bool isEmpty = GetData(); + if (isEmpty) { + return ""; + } + return "the text of the security component is out of range"; +} + std::string CompoRandomGenerator::GenerateRandomCompoStr(uint32_t type) { switch (type) { diff --git a/test/fuzztest/security_component/common/fuzz_common.h b/test/fuzztest/security_component/common/fuzz_common.h index ebf8c0b5f9d31cee5bb3b3bbf2ff2e0f69f61e13..b24bd0788b45d2c6861b9d149dc995a69b1917c6 100644 --- a/test/fuzztest/security_component/common/fuzz_common.h +++ b/test/fuzztest/security_component/common/fuzz_common.h @@ -30,6 +30,7 @@ public: {} uint32_t GetScType(); + std::string GetMessage(); std::string GenerateRandomCompoStr(uint32_t type); std::string ConstructLocationJson(); std::string ConstructSaveJson(); diff --git a/test/fuzztest/security_component/service/preregisterseccompprocessstub_fuzzer/preregisterseccompprocessstub_fuzz.cpp b/test/fuzztest/security_component/service/preregisterseccompprocessstub_fuzzer/preregisterseccompprocessstub_fuzz.cpp index db6d055484d48b42e077e7745f5d755fc6ecca37..b2847cfe2ffa8a32bf365981797c4484a023fc68 100644 --- a/test/fuzztest/security_component/service/preregisterseccompprocessstub_fuzzer/preregisterseccompprocessstub_fuzz.cpp +++ b/test/fuzztest/security_component/service/preregisterseccompprocessstub_fuzzer/preregisterseccompprocessstub_fuzz.cpp @@ -39,11 +39,13 @@ static void PreRegisterSecCompProcessStubFuzzTest(const uint8_t *data, size_t si MessageParcel input; SecCompRawdata inputData; MessageParcel reply; + CompoRandomGenerator generator(data, size); + uint32_t type = generator.GetScType(); if (!input.WriteInterfaceToken(ISecCompService::GetDescriptor())) { return; } - rawData.WriteUint32(1); + rawData.WriteUint32(type); SecCompEnhanceAdapter::EnhanceClientSerialize(rawData, inputData); input.WriteUint32(inputData.size); input.WriteRawData(inputData.data, inputData.size); diff --git a/test/fuzztest/security_component/service/reportsecuritycomponentclickeventstub_fuzzer/reportsecuritycomponentclickeventstub_fuzzer.cpp b/test/fuzztest/security_component/service/reportsecuritycomponentclickeventstub_fuzzer/reportsecuritycomponentclickeventstub_fuzzer.cpp index 0371ea3bac14a6ae441d33cdb738b5393e972abe..33586d0ee7f7cda1eab4f54b28f9547ef80cf195 100644 --- a/test/fuzztest/security_component/service/reportsecuritycomponentclickeventstub_fuzzer/reportsecuritycomponentclickeventstub_fuzzer.cpp +++ b/test/fuzztest/security_component/service/reportsecuritycomponentclickeventstub_fuzzer/reportsecuritycomponentclickeventstub_fuzzer.cpp @@ -129,6 +129,10 @@ static int32_t RegisterSecurityComponentStub(uint32_t type, const std::string& c auto service = std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); service->OnRemoteRequest(code, input, reply, option); + int32_t errCode = reply.ReadInt32(); + if (errCode != 0) { + return 0; + } if (!reply.ReadUint32(replyData.size)) { return 0; } @@ -152,6 +156,32 @@ static int32_t RegisterSecurityComponentStub(uint32_t type, const std::string& c return scId; } +static int32_t UnRegisterSecurityComponentStub(int32_t scId) +{ + uint32_t code = + static_cast(ISecCompServiceIpcCode::COMMAND_UNREGISTER_SECURITY_COMPONENT); + MessageParcel rawData; + MessageParcel input; + SecCompRawdata inputData; + MessageParcel reply; + SecCompRawdata replyData; + + if (!input.WriteInterfaceToken(ISecCompService::GetDescriptor())) { + return 0; + } + if (!rawData.WriteInt32(scId)) { + return 0; + } + SecCompEnhanceAdapter::EnhanceClientSerialize(rawData, inputData); + input.WriteUint32(inputData.size); + input.WriteRawData(inputData.data, inputData.size); + MessageOption option(MessageOption::TF_SYNC); + auto service = + std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); + service->OnRemoteRequest(code, input, reply, option); + return 0; +} + static void ReportSecurityComponentClickEventStubFuzzTest(const uint8_t *data, size_t size) { uint32_t code = static_cast(ISecCompServiceIpcCode::COMMAND_REPORT_SECURITY_COMPONENT_CLICK_EVENT); @@ -174,6 +204,9 @@ static void ReportSecurityComponentClickEventStubFuzzTest(const uint8_t *data, s return; } + if (!rawData.WriteString(generator.GetMessage())) { + return; + } sptr parcel = new (std::nothrow) SecCompClickEventParcel(); ConstructClickEvent(generator, parcel->clickInfoParams_); if (!rawData.WriteParcelable(parcel)) { @@ -195,6 +228,7 @@ static void ReportSecurityComponentClickEventStubFuzzTest(const uint8_t *data, s MessageOption option(MessageOption::TF_SYNC); auto service = std::make_shared(SA_ID_SECURITY_COMPONENT_SERVICE, true); service->OnRemoteRequest(code, input, reply, option); + UnRegisterSecurityComponentStub(scId); } } // namespace OHOS