diff --git a/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h b/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h index 44ec9a561a4e17486b092fa96e5eccb73b71647c..77b141b9996866797198628e465b1a3ca3277fe3 100644 --- a/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h +++ b/interfaces/innerkits/appverify/include/common/hap_byte_buffer.h @@ -59,7 +59,6 @@ public: DLL_EXPORT void Slice(); DLL_EXPORT int32_t Remaining() const; DLL_EXPORT bool HasRemaining() const; - DLL_EXPORT bool CopyPartialBuffer(const HapByteBuffer& other, int32_t len); DLL_EXPORT void Clear(); DLL_EXPORT bool IsEqual(const HapByteBuffer& other); DLL_EXPORT bool IsEqual(const std::string& other); @@ -72,9 +71,9 @@ private: static const int32_t MAX_PRINT_LENGTH; static const int32_t HEX_PRINT_LENGTH; std::unique_ptr buffer; - int32_t position; - int32_t limit; - int32_t capacity; + int32_t position = 0; + int32_t limit = 0; + int32_t capacity = 0; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/common/random_access_file.h b/interfaces/innerkits/appverify/include/common/random_access_file.h index ada93b2bd2c14c300d8a7d48638a557fd35e4947..8e67076eaf4703e612dde160c6e0d906811c246d 100644 --- a/interfaces/innerkits/appverify/include/common/random_access_file.h +++ b/interfaces/innerkits/appverify/include/common/random_access_file.h @@ -24,8 +24,8 @@ namespace Security { namespace Verify { struct MmapInfo { long long mmapPosition; - int32_t readMoreLen; - int32_t mmapSize; + int32_t readMoreLen = 0; + int32_t mmapSize = 0; char* mapAddr; }; @@ -44,7 +44,7 @@ private: bool CheckLittleEndian(); static const int32_t FILE_OPEN_FAIL_ERROR_NUM; static int32_t memoryPageSize; - int32_t fd; + int32_t fd = 0; long long fileLength; }; } // namespace Verify diff --git a/interfaces/innerkits/appverify/include/init/trusted_source_manager.h b/interfaces/innerkits/appverify/include/init/trusted_source_manager.h index ee5aa18209a6e0db2ac6ee4760a44013a252b73e..22f693f20b1edcdebf87172839c8e096759da2ef 100644 --- a/interfaces/innerkits/appverify/include/init/trusted_source_manager.h +++ b/interfaces/innerkits/appverify/include/init/trusted_source_manager.h @@ -33,7 +33,7 @@ struct HapAppSourceInfo { std::string profileSigningCertificate; std::string profileDebugSigningCertificate; std::string issuer; - int32_t maxCertsPath; + int32_t maxCertsPath = 0; StringVec critialcalCertExtension; }; diff --git a/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h b/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h index d77da42b6ef00f5cc4d98d0bf785fd97ee55996b..b09b5cf61e8fd88144fe774681bc42b7fbb447a1 100644 --- a/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h +++ b/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h @@ -30,7 +30,7 @@ struct HapTicketSourceInfo { std::string sourceName; std::string ticketSigningCert; std::string issuer; - int32_t maxCertsPath; + int32_t maxCertsPath = 0; StringVec critialcalCertExtension; }; diff --git a/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h b/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h index 193f401e5695aafce9415e8795a9045d15d88e3b..b793e837b1bfa47f9d35dd64b3852ac097bf6350 100644 --- a/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h +++ b/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h @@ -55,7 +55,7 @@ enum GetOptionalBlockResultCode { }; struct OptionalBlock { - int32_t optionalType; + int32_t optionalType = 0; HapByteBuffer optionalBlockValue; }; @@ -80,7 +80,7 @@ private: DLL_EXPORT int32_t GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const; private: - int32_t version; + int32_t version = 0; std::vector publicKeys; std::vector signatures; HapByteBuffer pkcs7SignBlock; diff --git a/interfaces/innerkits/appverify/include/provision/provision_info.h b/interfaces/innerkits/appverify/include/provision/provision_info.h index f55798fe249c1abc33fbedb5355b4e78a352c278..1ddcd0857b43aad4e28d057c56de3b38439f6982 100644 --- a/interfaces/innerkits/appverify/include/provision/provision_info.h +++ b/interfaces/innerkits/appverify/include/provision/provision_info.h @@ -64,8 +64,8 @@ struct DebugInfo { }; struct Validity { - int64_t notBefore; - int64_t notAfter; + int64_t notBefore = 0; + int64_t notAfter = 0; }; struct Metadata { diff --git a/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h b/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h index 8b3d156a9a2889caf4cd1afc210a7adfcdc11361..13ed7e83a2fd730d8be6784c6ae9cc80d02c02b9 100644 --- a/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h +++ b/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h @@ -40,17 +40,17 @@ enum HapBlobType { }; struct HapSignBlockHead { - int32_t version; - int32_t blockCount; + int32_t version = 0; + int32_t blockCount = 0; long long hapSignBlockSize; long long hapSignBlockMagicLo; long long hapSignBlockMagicHi; }; struct HapSubSignBlockHead { - uint32_t type; - uint32_t length; - uint32_t offset; + uint32_t type = 0; + uint32_t length = 0; + uint32_t offset = 0; }; class HapSigningBlockUtils { diff --git a/interfaces/innerkits/appverify/include/util/pkcs7_context.h b/interfaces/innerkits/appverify/include/util/pkcs7_context.h index ce86b381bef48ae9e039178097079b09e9551eed..5b26d52dd9e15f8e5470268c3a34fffc74502e76 100644 --- a/interfaces/innerkits/appverify/include/util/pkcs7_context.h +++ b/interfaces/innerkits/appverify/include/util/pkcs7_context.h @@ -32,7 +32,7 @@ using Pkcs7CertChains = std::vector; struct Pkcs7Context { bool needWriteCrl; - int32_t digestAlgorithm; + int32_t digestAlgorithm = 0; MatchingResult matchResult; std::string certIssuer; PKCS7* p7; diff --git a/interfaces/innerkits/appverify/include/util/signature_info.h b/interfaces/innerkits/appverify/include/util/signature_info.h index d35de7da6d9d706ec20e38758f21d1b6f492ee6d..0ebfd01e15c72078e028d18ff0645aa205763c3f 100644 --- a/interfaces/innerkits/appverify/include/util/signature_info.h +++ b/interfaces/innerkits/appverify/include/util/signature_info.h @@ -30,7 +30,7 @@ struct SignatureInfo { long long hapEocdOffset; HapByteBuffer hapEocd; std::vector optionBlocks; - int32_t version; + int32_t version = 0; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp b/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp index 9ff07f89a2b6fb992f19b6d0730f0c882eb09f59..aa37b823f70d1600d8f8765a0ffb8dcd6ab6148c 100644 --- a/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp +++ b/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp @@ -279,28 +279,6 @@ bool HapByteBuffer::HasRemaining() const return position < limit; } -bool HapByteBuffer::CopyPartialBuffer(const HapByteBuffer& other, int32_t len) -{ - int32_t readableDataLen = other.Remaining(); - if (readableDataLen < len) { - HAPVERIFY_LOG_ERROR(LABEL, "readableDataLen %{public}d less than len %{public}d", readableDataLen, len); - return false; - } - - buffer.reset(nullptr); - buffer = std::make_unique(len); - if (buffer != nullptr && other.GetBufferPtr() != nullptr) { - capacity = len; - limit = capacity; - if (memcpy_s(buffer.get(), capacity, (other.GetBufferPtr() + other.GetPosition()), len) != EOK) { - HAPVERIFY_LOG_ERROR(LABEL, "memcpy_s failed"); - return false; - } - } - position = 0; - return true; -} - void HapByteBuffer::Clear() { position = 0; diff --git a/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp b/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp index ec3352dee0ec16979ee2444ff94b51d97a780862..e0b5e3116a23bc87c047c666640255c252a8e481 100644 --- a/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp +++ b/interfaces/innerkits/appverify/src/init/json_parser_utils.cpp @@ -41,7 +41,7 @@ bool JsonParserUtils::ReadTrustedRootCAFromJson(nlohmann::json& jsonObj, std::string jsonStr = buf.str(); jsonObj = nlohmann::json::parse(jsonStr, nullptr, false); - if (!jsonObj.is_structured()) { + if (jsonObj.is_discarded() || (!jsonObj.is_structured())) { error += "parse jsonStr failed"; return false; } diff --git a/interfaces/innerkits/appverify/src/provision/provision_verify.cpp b/interfaces/innerkits/appverify/src/provision/provision_verify.cpp index 8f1cd826f53a77aafb5070ffbf197ab7ef31a091..df34c51955a718e0849e69c344563077d49231a5 100644 --- a/interfaces/innerkits/appverify/src/provision/provision_verify.cpp +++ b/interfaces/innerkits/appverify/src/provision/provision_verify.cpp @@ -250,7 +250,7 @@ void from_json(const json& obj, ProvisionInfo& out) AppProvisionVerifyResult ParseProvision(const string& appProvision, ProvisionInfo& info) { json obj = json::parse(appProvision, nullptr, false); - if (!obj.is_structured()) { + if (obj.is_discarded() || (!obj.is_structured())) { HAPVERIFY_LOG_ERROR(LABEL, "Parsing appProvision failed. json: %{public}s", appProvision.c_str()); return PROVISION_INVALID; } @@ -369,7 +369,7 @@ AppProvisionVerifyResult ParseAndVerify(const string& appProvision, ProvisionInf AppProvisionVerifyResult ParseProfile(const std::string& appProvision, ProvisionInfo& info) { json obj = json::parse(appProvision, nullptr, false); - if (!obj.is_structured()) { + if (obj.is_discarded() || (!obj.is_structured())) { HAPVERIFY_LOG_ERROR(LABEL, "Parsing appProvision failed. json: %{public}s", appProvision.c_str()); return PROVISION_INVALID; } diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h index a527bf37644f110686cf0c7634e43b6226663a9a..c27469478ac8fe6720062acd7e5d5990a5c2f9bf 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h @@ -21,7 +21,6 @@ int32_t HapByteBuffer001(void); int32_t GetIntAndPutOperation001(void); int32_t Slice001(void); -int32_t CopyPartialBuffer001(void); int32_t IsEqual001(void); int32_t IsEqual002(void); #endif // HAP_BYTE_BUFFER_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp index 832b6cdf652a26bc97afcebd888bf6cb7f7ed082..d2b7852cf07be2a23be9e83b414511f2de7786ad 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp @@ -185,37 +185,6 @@ HWTEST_F (HapByteBufferTest, Slice001, TestSize.Level1) ASSERT_TRUE(buffer1.HasRemaining()); } -/** - * @tc.name: Test HapByteBuffer function of CopyPartialBuffer - * @tc.desc: The static function will copy data from an object, detect the data is right; - * @tc.type: FUNC - */ -HWTEST_F (HapByteBufferTest, CopyPartialBuffer001, TestSize.Level1) -{ - /* - * @tc.steps: step1. Copy 8 bytes data from 10st-position in a 15 bytes length buffer. - * @tc.expected: step1. The return result is false. - */ - HapByteBuffer buffer1(TEST_HAPBYTEBUFFER_LENGTH); - buffer1.PutInt32(0, TEST_HAPBYTEBUFFER_INT32_DATA); - buffer1.PutInt32(sizeof(int), TEST_HAPBYTEBUFFER_INT32_DATA_2); - HapByteBuffer buffer2(TEST_HAPBYTEBUFFER_LENGTH); - buffer1.SetPosition(TEST_HAPBYTEBUFFER_POSITION); - ASSERT_FALSE(buffer2.CopyPartialBuffer(buffer1, TEST_HAPBYTEBUFFER_LENGTH_2)); - /* - * @tc.steps: step2. Copy 8 bytes data from first-position in a 15 bytes length buffer. - * @tc.expected: step2. Buffer2 return is targeted value. - */ - buffer1.Clear(); - buffer2.CopyPartialBuffer(buffer1, TEST_HAPBYTEBUFFER_LENGTH_2); - int32_t target1; - ASSERT_TRUE(buffer2.GetInt32(target1)); - ASSERT_EQ(target1, TEST_HAPBYTEBUFFER_INT32_DATA); - int32_t target2; - ASSERT_TRUE(buffer2.GetInt32(target2)); - ASSERT_EQ(target2, TEST_HAPBYTEBUFFER_INT32_DATA_2); -} - /** * @tc.name: Test HapByteBuffer function of IsEqual001 * @tc.desc: The static function will return two object whether is equal.