diff --git a/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp index 4c838e43394bb26725c903c55d7baa3e949927ae..7ef98cf42a025e9473802264f88f1b73def44a54 100644 --- a/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/codesigning/codesigning_fuzzer/codesigning_fuzzer.cpp @@ -23,7 +23,7 @@ namespace SignatureTools { bool SignBlockInfoObjectBuild(const uint8_t* data, size_t size) { SignBlockInfo object; - std::vector sig{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, 1 }; + std::vector sig{data, data + size}; object.SetFileDigest(sig); return true; } @@ -31,7 +31,7 @@ bool SignBlockInfoObjectBuild(const uint8_t* data, size_t size) bool SigningBlockObjectBuild(const uint8_t* data, size_t size) { int32_t type = 1; - std::vector sig{ 48, -126, 7, -46, 6, 9, 42, -122, 72, -122, -9, 13, 1 }; + std::vector sig{data, data + size}; SigningBlock object(type, sig); return true; } diff --git a/hapsigntool_cpp_test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp index beb0a2fa1bde0654afd674e4500ccbba5241fa6f..d1d44945a341321d70aaae9cc6e93364a02e114b 100644 --- a/hapsigntool_cpp_test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/common/bytebuffer/bytebufferinit_fuzzer/bytebufferinit_fuzzer.cpp @@ -27,7 +27,7 @@ void ByteBufferTest001(const uint8_t* data, size_t size) int32_t type = 4; int32_t len = 100; int16_t value = 6; - uint8_t vValue = 16; + uint8_t vValue = *data; const char dataTest[] = "hello world!"; ByteBuffer bytebuffer; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp index e78384057f446c8fa674e0bd44de155c0476be26..ec57ff2a4b7d9810cf583574ab8360d02a80f774 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca001_fuzzer/generateca001_fuzzer.cpp @@ -42,7 +42,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string extKeyUsage = "codeSignature"; std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; std::string keyAlg = "ECC"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA256withECDSA"; int basicConstraintsPathLen = 0; std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp index 6f74aa6535c3e23c79ba0b0a75e98c4a1c252187..901e17fc3df26362d293817be84558b910f0cf84 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca002_fuzzer/generateca002_fuzzer.cpp @@ -32,7 +32,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) if (!data || !size) { return true; } - std::string path = "/data/test/generateCA/root-ca1.cer"; + std::string path = std::string(reinterpret_cast(data), size); CertTools::ReadfileToX509(path); return true; } diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp index dd80863fca675b63f727fc2b13e4eb134ddd31ee..ca236a863b8dfc5859bbde3b14af6a369bc959a0 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca004_fuzzer/generateca004_fuzzer.cpp @@ -39,7 +39,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string keyAlias = "oh-app1-key-v1"; std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; std::string issuerKeyAlias = "oh-app-sign-srv-ca-key-v1"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA384withECDSA"; std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; std::string rootCaCertFile = "/data/test/generateCA/root-ca1.cer"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp index e0ebd715ab108b236a82ec47ae6b16952673242e..c9efbdc88187d4768960449e47c7a21aa0884d29 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca005_fuzzer/generateca005_fuzzer.cpp @@ -38,7 +38,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::shared_ptr params = std::make_shared(); std::string keyAlias = "oh-root-ca-key-v1"; std::string keyAlg = "ECC"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA384withECDSA"; int basicConstraintsPathLen = 0; std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp index 1de804792c1bbd5d9340c359d6715dc64eeb71d3..8873eb50a37c506bcc5a6219190179a42b69dfd1 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca006_fuzzer/generateca006_fuzzer.cpp @@ -39,7 +39,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string keyAlias = "oh-app-sign-srv-ca-key-v1"; std::string issuerKeyAlias = "oh-root-ca-key-v1"; std::string issuer = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Root CA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA384withECDSA"; int basicConstraintsPathLen = 0; std::string keyAlg = "ECC"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp index 22be79f9a8e9598b57670f49a58040f5da1b11c2..2f08531aed7ee2d6bedec9454d6e98b8e36494aa 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca007_fuzzer/generateca007_fuzzer.cpp @@ -38,7 +38,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::shared_ptr params = std::make_shared(); std::string keyAlias = "oh-app1-key-v1"; std::string keyAlg = "ECC"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA256withECDSA"; std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; char keyPwd[] = "123456"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp index 4ddf13794e61b1baa0cd01b23de983f897b7059b..ad61982039cfc58364cceea44123f9f2ff56bc41 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca008_fuzzer/generateca008_fuzzer.cpp @@ -35,7 +35,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) } std::shared_ptr api = std::make_shared(); X509* cert = X509_new(); - const std::string path = "/data/test/generateCA/cer"; + const std::string path = std::string(reinterpret_cast(data), size); return api->OutPutCert(cert, path); } } diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp index 11796f89f64702d9d83ae597e7c69f8a5c740966..245f049dc9c4bc10bb5ed2827891ad7daa5ca3a0 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca009_fuzzer/generateca009_fuzzer.cpp @@ -40,7 +40,7 @@ bool TestGenerateSubCert(const uint8_t* data, size_t size) std::string keystoreFile = "./generateCA/OpenHarmony.p12"; char keystorePwd[] = "123456"; std::string signAlg = "SHA256withECDSA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; char isksPwd[] = "123456"; (*params)["keystorePwd"] = keystorePwd; @@ -72,7 +72,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string keystoreFile = "./generateCA/OpenHarmony.p12"; std::string signAlg = "SHA256withECDSA"; std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Openharmony Application CA"; - std::string issuer = "C=CN,O=OpenHarmony_test,OU=OpenHarmony Community,CN= Openharmony Application SUB CA"; + std::string issuer(reinterpret_cast(data), size); bool keyUsage = true; std::string basicConstraints = "true"; std::string basicConstraintsCritical = "true"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp index bcfdd4cea327c55eb4338374c31fd9b6afe26163..6b011cdc2e35be78a816cceffbb45a0c0511e566 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca010_fuzzer/generateca010_fuzzer.cpp @@ -37,7 +37,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string keyAlias = "oh-app1-key-v1"; std::string issuerkeyAlias = "oh-root-ca-key-v1"; std::string keyAlg = "ECC"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA384withECDSA"; int basicConstraintsPathLen = 0; std::string keystoreFile = "./generateCA/OpenHarmony.p12"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp index c5e2d25e27cf7c7fac11afb15b0015c915055b82..5245ec6c72624966c34e07850a7ff4d002e1b207 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca011_fuzzer/generateca011_fuzzer.cpp @@ -37,7 +37,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string keyAlias = "oh-app1-key-v1"; std::string issuerkeyAlias = "oh-root-ca-key-v1"; std::string keyAlg = "ECC"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA384withECDSA"; int basicConstraintsPathLen = 0; std::string keystoreFile = "./generateCA/OpenHarmony.p12"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp index 61d8cc8001dcc5fe76f3c82b5fecf572278561d2..e0987dbfc12f19dbee2a8744f2597a73b7c5ef27 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca012_fuzzer/generateca012_fuzzer.cpp @@ -37,7 +37,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string keyAlias = "oh-app-sign-srv-ca-key-v1"; std::string issuerkeyAlias = "oh-root-ca-key-v1"; std::string keyAlg = "ECC"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN= Application Signature Service CA"; + std::string subject = std::string(reinterpret_cast(data), size); std::string signAlg = "SHA384withECDSA"; int basicConstraintsPathLen = 0; std::string keystoreFile = "/data/test/generateCA/OpenHarmony.p12"; diff --git a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca016_fuzzer/generateca016_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca016_fuzzer/generateca016_fuzzer.cpp index 85bfaa909e9429dea484c48b9b6018f20c5be93b..89837685bf07b4655e7bf8b0de5ff3949ae4abea 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_ca/generateca016_fuzzer/generateca016_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_ca/generateca016_fuzzer/generateca016_fuzzer.cpp @@ -32,7 +32,7 @@ namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { Options option; - bool ret = CmdUtil::String2Bool(&option, "s"); + bool ret = CmdUtil::String2Bool(&option, std::string(reinterpret_cast(data), size)); return ret; } } diff --git a/hapsigntool_cpp_test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp index 778e0df3858778a232c739f5381cc9c8b598e069..197bee04b21d09e766078d1596e5e12f91e7b647 100644 --- a/hapsigntool_cpp_test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/generate_csr/generatecsr001_fuzzer/generatecsr001_fuzzer.cpp @@ -25,7 +25,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int keySize = 256; std::string algorithm = "ECC"; std::string signAlgorithm = "SHA256withECDSA"; - std::string subject = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=App1 Release"; + std::string subject = std::string(reinterpret_cast(data), size); KeyStoreHelper keyStoreHelper; EVP_PKEY* keyPair = keyStoreHelper.GenerateKeyPair(algorithm, keySize); if (!keyPair) { diff --git a/hapsigntool_cpp_test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp index 3cf9f8f3ad936a44f79cd96b45ef29fbd3e8e571..1ffdeeca962f1444adb2954e5bc61397dd2c6f4a 100644 --- a/hapsigntool_cpp_test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/hapsign/hapsign001_fuzzer/hapsign001_fuzzer.cpp @@ -38,7 +38,7 @@ bool HapSignTest001(const uint8_t* data, size_t size) std::string mode = "localSign"; std::string keyAlias = "oh-app1-key-v1"; - std::string signAlg = "SHA256w"; + std::string signAlg = std::string(reinterpret_cast(data), size); std::string signCode = "0"; std::string appCertFile = "./hapSign/app-release1.pem"; std::string profileFile = "./hapSign/signed-profile.p7b"; @@ -106,12 +106,12 @@ bool HapSignTest003(const uint8_t* data, size_t size) X509* cert = X509_new(); X509* cert1 = X509_new(); X509_REQ* issuerReq = X509_REQ_new(); - std::string issuername = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string issuername(reinterpret_cast(data), size); X509_NAME* issName = BuildDN(issuername, issuerReq); CertTools::SetCertIssuerName(cert, issName); CertTools::SetCertIssuerName(cert1, issName); - std::string subjectname = "C=CN,O=OpenHarmony,OU=OpenHarmony Community,CN=Application Signature Service CA"; + std::string subjectname(reinterpret_cast(data), size); X509_NAME* subName = BuildDN(subjectname, issuerReq); X509_set_subject_name(cert, subName); X509_set_subject_name(cert1, subName); @@ -140,7 +140,7 @@ bool HapSignTest004(const uint8_t* data, size_t size) std::shared_ptr params = std::make_shared(); std::string mode = "localSign"; - std::string keyAlias = "oh-app1-key-v1"; + std::string keyAlias(reinterpret_cast(data), size); std::string signAlg = "SHA256withECDSA"; std::string signCode = "1"; std::string appCertFile = "./hapSign/app-release1.pem"; @@ -195,7 +195,7 @@ bool HapSignTest006(const uint8_t* data, size_t size) std::string mode = "remoteSign"; std::string keyAlias = "oh-app1-key-v1"; std::string signAlg = "SHA256withECDSA"; - std::string signCode = "1"; + std::string signCode(reinterpret_cast(data), size); std::string profileFile = "./hapSign/signed-profile.p7b"; std::string inFile = "./hapSign/phone-default-unsigned.hap"; std::string outFile = "./hapSign/phone-default-signed.hap"; @@ -239,7 +239,7 @@ bool HapSignTest007(const uint8_t* data, size_t size) std::string signCode = "1"; std::string appCertFile = "./hapSign/app-release1.pem"; std::string profileFile = "./hapSign/signed-profile.p7b"; - std::string profileSigned = "1"; + std::string profileSigned(reinterpret_cast(data), size); std::string inFile = "./hapSign/phone-default-unsigned"; std::string keystoreFile = "./hapSign/ohtest.p12"; std::string outFile = "./hapSign/phone-default-signed.hap"; diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp index bd1f4c6f8cfc8cc2b0fc4d6636c8b5a7625ccbba..2f1147fe38b7c3787da84017afaad18271753991 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd007_fuzzer/processcmd007_fuzzer.cpp @@ -22,14 +22,15 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } char arg0[] = ""; char arg1[] = "generate-keypair"; char arg2[] = "-keyAlias"; - char arg3[] = "oh-app1-key-v1"; + char* arg3 = new char[size]; + memcpy_s(arg3, size, data, size); char arg4[] = "-keyPwd"; char arg5[] = "123456"; char arg6[] = "-keyAlg"; @@ -45,6 +46,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 14; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg3; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp index 08f718f1c536e9ca8d63ada21a84319c64b85fbc..9bde8a038ce7a2769f97b9521230749cc5f64521 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd008_fuzzer/processcmd008_fuzzer.cpp @@ -22,14 +22,15 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } char arg0[] = ""; char arg1[] = "generate-keypair"; char arg2[] = "-keyAlias"; - char arg3[] = "oh-app1-key-v1"; + char* arg3 = new char[size]; + memcpy_s(arg3, size, data, size); char arg4[] = "-keyPwd"; char arg5[] = "123456"; char arg6[] = "-keyAlg"; @@ -45,6 +46,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 14; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg3; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp index 7de94b6277860087b2594e6c066df3c0537b6753..6368a3842af2ba349df1c2e193754f60741b4878 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd009_fuzzer/processcmd009_fuzzer.cpp @@ -22,14 +22,15 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } char arg0[] = ""; char arg1[] = "generate-csr"; char arg2[] = "-keyAlias"; - char arg3[] = "oh-app1-key-v1"; + char* arg3 = new char[size]; + memcpy_s(arg3, size, data, size); char arg4[] = "-keyPwd"; char arg5[] = "123456"; char arg6[] = "-subject"; @@ -47,6 +48,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 16; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg3; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp index 3748eab8d54846f0563fddac87763b9cbac86677..a5466ee123d80efc88b8c8f7dde446762f499ddc 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd010_fuzzer/processcmd010_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -33,7 +33,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg4[] = "-keyPwd"; char arg5[] = "123456"; char arg6[] = "-subject"; - char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Root CA"; + char* arg7 = new char[size]; + memcpy_s(arg7, size, data, size); char arg8[] = "-validity"; char arg9[] = "365"; char arg10[] = "-signAlg"; @@ -53,6 +54,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 22; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg7; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp index a0e6ddcc2adea40cfeb3ba55902f9d4b7a4cc3d2..d936a10a6c76eacdc0c613990d156edc5d0ee269 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd011_fuzzer/processcmd011_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-root-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN= Application Signature Service CA"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-keystoreFile"; char arg13[] = "./generateKeyPair/OpenHarmony.p12"; char arg14[] = "-keystorePwd"; @@ -60,6 +61,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 28; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp index fa43c1052c26c48c1e14f60c49783dfad5ebb7b3..bbf63ca946e78aa7588b45f49addb640ce62de12 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd012_fuzzer/processcmd012_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-root-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN= Application Signature Service CA"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-keystoreFile"; char arg13[] = "./generateKeyPair/OpenHarmony.p12"; char arg14[] = "-keystorePwd"; @@ -60,6 +61,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 28; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp index 3e9966cdc696274a4baa14224bddc04a6c1c75a0..16a11e40c35b65d658f5f6ce1fb68de9078c9fa8 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd013_fuzzer/processcmd013_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -33,7 +33,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg4[] = "-keyPwd"; char arg5[] = "123456"; char arg6[] = "-issuer"; - char arg7[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=Application Signature Service CA"; + char* arg7 = new char[size]; + memcpy_s(arg7, size, data, size); char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-app-sign-srv-ca-key-v1"; char arg10[] = "-subject"; @@ -62,6 +63,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 30; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg7; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp index a239378b15fb3bfa62d7cff672675164b7fbc295..676998d3b2da8269e8d5ffc948d84733739b2079 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd014_fuzzer/processcmd014_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-app-sign-srv-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-validity"; char arg13[] = "365"; char arg14[] = "-signAlg"; @@ -62,6 +63,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 30; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp index eb713a18ee9d4e3cae47d211d08de7ea8cf33871..1126ca121f82db0bb87c8c0b92c63ec730618b26 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd015_fuzzer/processcmd015_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-profile-sign-srv-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU = OpenHarmony Community; CN = App1 Release"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-validity"; char arg13[] = "365"; char arg14[] = "-signAlg"; @@ -55,6 +56,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 24; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp index eb790fc53be3f679c62a1c07244d61065ffa5355..910f72ad535e1474d7883806c6fb7147f3626af3 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd016_fuzzer/processcmd016_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-signAlg"; char arg9[] = "SHA384withECDSA"; char arg10[] = "-inFile"; - char arg11[] = "./generateKeyPair/profile.json"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-keystoreFile"; char arg13[] = "./generateKeyPair/OpenHarmony.p12"; char arg14[] = "-keystorePwd"; @@ -51,6 +52,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 20; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp index 36ddd6015da88779cf8baee4330fab4fa0248f87..3037fbf69bf58be1f72dbcd6a93478bc4e9404ad 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd017_fuzzer/processcmd017_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -31,11 +31,13 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg2[] = "-inFile"; char arg3[] = "./generateKeyPair/signed-profile.p7b"; char arg4[] = "-outFile"; - char arg5[] = "./generateKeyPair/VerifyResult.json"; + char* arg5 = new char[size]; + memcpy_s(arg5, size, data, size); char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5 }; int argc = 6; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg5; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp index 08746f688dabd838a1662d635e56ac6099c0b7b5..6bad70d7e445422994215185a4be68ed14bbacfa 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd018_fuzzer/processcmd018_fuzzer.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } char arg0[] = ""; @@ -50,19 +50,21 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg20[] = "-keystorePwd"; char arg21[] = "123456"; char arg22[] = "-outFile"; - char arg23[] = "./generateKeyPair/entry-default-signed-so.hap"; + char* arg23 = new char[size]; + memcpy_s(arg23, size, data, size); char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23}; int argc = 24; CodeSigning obj; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg23; return ret; } bool RemoteSignTest(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -91,19 +93,21 @@ bool RemoteSignTest(const uint8_t* data, size_t size) char arg18[] = "-onlineAuthMode"; char arg19[] = "./generateKeyPair/OpenHarmony.p12"; char arg20[] = "-username"; - char arg21[] = "123456"; + char* arg21 = new char[size]; + memcpy_s(arg21, size, data, size); char arg22[] = "-userPwd"; char arg23[] = "123456"; char* argv[] = {arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23}; int argc = 24; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg21; return ret; } bool SignElf(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } char arg0[] = ""; @@ -111,7 +115,8 @@ bool SignElf(const uint8_t* data, size_t size) char arg2[] = "-keyAlias"; char arg3[] = "oh-app1-key-v1"; char arg4[] = "-keyPwd"; - char arg5[] = "123456"; + char* arg5 = new char[size]; + memcpy_s(arg5, size, data, size); char arg6[] = "-mode"; char arg7[] = "localSign"; char arg8[] = "-signCode"; @@ -136,12 +141,13 @@ bool SignElf(const uint8_t* data, size_t size) arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25}; int argc = 26; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg5; return ret; } bool SignBin(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } char arg0[] = ""; @@ -151,7 +157,8 @@ bool SignBin(const uint8_t* data, size_t size) char arg4[] = "-keyPwd"; char arg5[] = "123456"; char arg6[] = "-mode"; - char arg7[] = "localSign"; + char* arg7 = new char[size]; + memcpy_s(arg7, size, data, size); char arg8[] = "-signCode"; char arg9[] = "1"; char arg10[] = "-signAlg"; @@ -174,6 +181,7 @@ bool SignBin(const uint8_t* data, size_t size) arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25}; int argc = 26; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg7; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp index 0d78fce9de8b54d811f26cd60a12ec9e99c935de..f37b4a997ec67b9be05aeec70247ab26b97bd194 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd019_fuzzer/processcmd019_fuzzer.cpp @@ -28,7 +28,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -39,7 +39,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg4[] = "-outCertChain"; char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; char arg6[] = "-outProfile"; - char arg7[] = "./generateKeyPair/app-profile.p7b"; + char* arg7 = new char[size]; + memcpy_s(arg7, size, data, size); char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 }; int argc = 8; @@ -49,7 +50,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) bool VerifyElf(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -60,7 +61,8 @@ bool VerifyElf(const uint8_t* data, size_t size) char arg4[] = "-outCertChain"; char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; char arg6[] = "-outProfile"; - char arg7[] = "./generateKeyPair/app-profile.p7b"; + char* arg7 = new char[size]; + memcpy_s(arg7, size, data, size); char arg8[] = "-inForm"; char arg9[] = "elf"; char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; @@ -72,7 +74,7 @@ bool VerifyElf(const uint8_t* data, size_t size) bool VerifyBin(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -83,13 +85,15 @@ bool VerifyBin(const uint8_t* data, size_t size) char arg4[] = "-outCertChain"; char arg5[] = "./generateKeyPair/app-sign-srv-ca1.cer"; char arg6[] = "-outProfile"; - char arg7[] = "./generateKeyPair/app-profile.p7b"; + char* arg7 = new char[size]; + memcpy_s(arg7, size, data, size); char arg8[] = "-inForm"; char arg9[] = "bin"; char* argv[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }; int argc = 10; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg7; return ret; } @@ -107,7 +111,7 @@ bool TestDatastructure(const uint8_t* data, size_t size) bool TestFileUtils(const uint8_t* data, size_t size) { - std::string bytes; + std::string bytes(reinterpret_cast(data), size); std::string file; bool flag = FileUtils::WriteByteToOutFile(bytes, file); FileUtils::DelDir(file); diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp index ae9dc83249e2bbf1fed320acf8e67f7312927cc4..20ed79664e993941c58a4e8c506ed8bfb065dc4c 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd020_fuzzer/processcmd020_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-app-sign-srv-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-validity"; char arg13[] = "365"; char arg14[] = "-signAlg"; @@ -62,6 +63,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 30; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp index 01d822dd56139fa63577a4bf509999ac34bc2252..95957f99c14a77770fb22460824db7186807c5b7 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd021_fuzzer/processcmd021_fuzzer.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace SignatureTools { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -37,7 +37,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-app-sign-srv-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-validity"; char arg13[] = "365"; char arg14[] = "-signAlg"; @@ -62,6 +63,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) int argc = 30; bool ret = ParamsRunTool::ProcessCmd(argv, argc); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp index 4f4bb8d47d4ebaf32b356f5b216931553da3a371..34b88eba5965aa5581ea0f33f0357bd202c4bab4 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd022_fuzzer/processcmd022_fuzzer.cpp @@ -96,7 +96,7 @@ bool GenerateAppCertTest3() } bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { - if (!data || !size) { + if (!data || !size || size <= 0) { return true; } @@ -111,7 +111,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) char arg8[] = "-issuerKeyAlias"; char arg9[] = "oh-app-sign-srv-ca-key-v1"; char arg10[] = "-subject"; - char arg11[] = "C=CN;O=OpenHarmony;OU=OpenHarmony Community;CN=App1 Release"; + char* arg11 = new char[size]; + memcpy_s(arg11, size, data, size); char arg12[] = "-validity"; char arg13[] = "365"; char arg14[] = "-signAlg"; @@ -140,6 +141,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) GenerateAppCertTest2(); ret = GenerateAppCertTest3(); + delete[] arg11; return ret; } } // namespace SignatureTools diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp index eccf98d9a08dc2805acc9f613a786646e2e96ead..66c0bd6ea9c075ab3eb1087db54b291bb02c2b24 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd023_fuzzer/processcmd023_fuzzer.cpp @@ -30,10 +30,10 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) } X509* cert = X509_new(); std::vector certChain; - std::string inputType = "clientAuthentication"; + std::string inputType(reinterpret_cast(data), size); CmdUtil::VerifyType(inputType); Options options; - std::string key1 = "key1"; + std::string key1(reinterpret_cast(data), size); std::string key2 = "key2"; bool status = true; (options)["booltype"] = status; diff --git a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp index 748a4bfa7966cc20cd7269c6bc37e20503a57eef..161721afb81a4fafa03903593cd3b217474d7b93 100644 --- a/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/process_cmd/processcmd024_fuzzer/processcmd024_fuzzer.cpp @@ -32,8 +32,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) } Params param; - std::string str; - std::string algName; + std::string str(reinterpret_cast(data), size); + std::string algName(reinterpret_cast(data), size); int algId = 256; std::vector paramFields; std::vector fileBytes; diff --git a/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp index 8407d466877f8622eb1bd78a5e581a569777b2e8..a46c2e1a87346c895704998c0929aaa850d6751a 100644 --- a/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/profile/profile001_fuzzer/profile001_fuzzer.cpp @@ -85,51 +85,7 @@ bool SignProfileTest002(const uint8_t* data, size_t size) bool SignProfileTest003(const uint8_t* data, size_t size) { - ASN1_TIME* time_ = ASN1_TIME_new(); - time_t now; - if (time(&now) < 0) { - return false; - } - ASN1_TIME_set(time_, now); - std::string result = PKCS7Data::GetASN1Time(time_); - ASN1_TIME_free(time_); - return result.empty() == false; -} - -bool SignProfileTest004(const uint8_t* data, size_t size) -{ - ProfileInfo info; - info.type = ProvisionType::RELEASE; - ProfileInfo info2(info); - return true; -} - -bool SignProfileTest005(const uint8_t* data, size_t size) -{ - std::string provision = "{\"app-distribution-type\": \"app_gallery\",\"b" - "undle-info\":{\"app-feature\":\"hos_system_app\",\"bundle-name\":\"com.Op" - "enHarmony.app.test\",\"developer-id\":\"OpenHarmony\",\"distribution-certif" - "icate\":\"-----BEGIN CERTIFICATE-----\\n" - "MIICMzCCAbegAwIBAgIEaOC/zDAMBggqhkjOPQQDAwUAMGMxCzAJBgNVBAYTAkNO\\n" - "MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh\\n" - "bTEjMCEGA1UEAxMaT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gQ0EwHhcNMjEwMjAy\\n" - "MTIxOTMxWhcNNDkxMjMxMTIxOTMxWjBoMQswCQYDVQQGEwJDTjEUMBIGA1UEChML\\n" - "T3Blbkhhcm1vbnkxGTAXBgNVBAsTEE9wZW5IYXJtb255IFRlYW0xKDAmBgNVBAMT\\n" - "H09wZW5IYXJtb255IEFwcGxpY2F0aW9uIFJlbGVhc2UwWTATBgcqhkjOPQIBBggq\\n" - "hkjOPQMBBwNCAATbYOCQQpW5fdkYHN45v0X3AHax12jPBdEDosFRIZ1eXmxOYzSG\\n" - "JwMfsHhUU90E8lI0TXYZnNmgM1sovubeQqATo1IwUDAfBgNVHSMEGDAWgBTbhrci\\n" - "FtULoUu33SV7ufEFfaItRzAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFPtxruhl\\n" - "cRBQsJdwcZqLu9oNUVgaMAwGCCqGSM49BAMDBQADaAAwZQIxAJta0PQ2p4DIu/ps\\n" - "LMdLCDgQ5UH1l0B4PGhBlMgdi2zf8nk9spazEQI/0XNwpft8QAIwHSuA2WelVi/o\\n" - "zAlF08DnbJrOOtOnQq5wHOPlDYB4OtUzOYJk9scotrEnJxJzGsh/\\n" - "-----END CERTIFICATE-----\\n" - "\"},\"debug-info\":{\"device-id-type\":\"udid\",\"device-ids\":[\"69C75" - "05BE341BDA5948C3C0CB44ABCD530296054159EFE0BD16A16CD0129CC42\",\"7EED0650" - "6FCE6325EB2E2FAA019458B856AB10493A6718C7679A73F958732865\"]},\"iss" - "uer\":\"pki_internal\",\"permissions\":{\"restricted-permissions\":" - "[\"\"]},\"type\":\"release\",\"uuid\":\"fe686e1b-3770-4824-a938-961b140" - "a7c98\",\"validity\":{\"not-after\":1705127532,\"not-before\":16105195" - "32},\"version-code\":1,\"version-name\":\"1.0.0\"}"; + std::string provision(reinterpret_cast(data), size); ProfileInfo info; AppProvisionVerifyResult result = ParseAndVerify(provision, info); return result == AppProvisionVerifyResult::PROVISION_OK; @@ -140,8 +96,6 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) SignProfileTest001(data, size); SignProfileTest002(data, size); SignProfileTest003(data, size); - SignProfileTest004(data, size); - SignProfileTest005(data, size); return true; } } diff --git a/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp index aa7ac7b95bd6acbb6d54497581116d6c81db778f..7ad00a26bc62e482be2e877915fe5171c521a9dd 100644 --- a/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/utils/hapsignerblockutils_fuzzer/hapsignerblockutils_fuzzer.cpp @@ -25,7 +25,8 @@ const std::string pathFile = "./zip/tmp.hap"; void HapSignerBlockUtilsFunc(const uint8_t* data, size_t size) { SignatureInfo info; - HapSignerBlockUtils::CreatTestZipFile(pathFile, info); + std::string name(reinterpret_cast(data), size); + HapSignerBlockUtils::CreatTestZipFile(pathFile + name, info); HapSubSignBlockHead signBlock; HapSubSignBlockHead profileBlock; diff --git a/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp index ffb11d35595ea120c7fc778ee6461337d9c82f30..754b70c94e3fe603b49418ccacee672db41166cd 100644 --- a/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/zip/randomaccessfileinputoutput_fuzzer/randomaccessfileinputoutput_fuzzer.cpp @@ -41,7 +41,8 @@ void RandomAccessFileReadFileFunc(const uint8_t* data, size_t size) void RandomAccessFileInputConstructor(const uint8_t* data, size_t size) { RandomAccessFile file; - if (!file.Init(UNSIGNED_HAP_FILE_PATH)) { + std::string name(reinterpret_cast(data), size); + if (!file.Init(UNSIGNED_HAP_FILE_PATH + name)) { return; } int64_t fileLength = file.GetLength(); @@ -52,7 +53,8 @@ void RandomAccessFileInputConstructor(const uint8_t* data, size_t size) void RandomAccessFileOutputConstructor(const uint8_t* data, size_t size) { RandomAccessFile file; - if (!file.Init(UNSIGNED_HAP_FILE_PATH)) { + std::string name(reinterpret_cast(data), size); + if (!file.Init(UNSIGNED_HAP_FILE_PATH + name)) { return; } RandomAccessFileOutput fileOutput(&file); diff --git a/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp b/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp index 8e951464b1799c159054338845389071c0cc91ca..c0674d249d5c4d3f40af70736c245467fbc18e7f 100644 --- a/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp +++ b/hapsigntool_cpp_test/fuzztest/zip/zipsigner_fuzzer/zipsigner_fuzzer.cpp @@ -32,8 +32,9 @@ const char* DATA_DESC_HAP_FILE_PATH = "./zip/data_descriptor_hap.hap"; void ZipSignerCompleteFlowFunc(const uint8_t* data, size_t size) { - std::ifstream inputFile(SIGNED_HAP_FILE_PATH, std::ios::binary); - std::ofstream outputFile(OUT_HAP_FILE_PATH, std::ios::binary | std::ios::trunc); + std::string name(reinterpret_cast(data), size); + std::ifstream inputFile(SIGNED_HAP_FILE_PATH + name, std::ios::binary); + std::ofstream outputFile(OUT_HAP_FILE_PATH + name, std::ios::binary | std::ios::trunc); auto zip = std::make_shared(); if (!zip->Init(inputFile)) { return; @@ -126,7 +127,8 @@ void CentralDirectoryInfoFunc(const uint8_t* data, size_t size) void DataDescriptorInfoFunc(const uint8_t* data, size_t size) { - std::ifstream inputFile(DATA_DESC_HAP_FILE_PATH, std::ios::binary); + std::string name(reinterpret_cast(data), size); + std::ifstream inputFile(DATA_DESC_HAP_FILE_PATH + name, std::ios::binary); auto zip = std::make_shared(); if (!zip->Init(inputFile)) { return; @@ -148,7 +150,8 @@ void DataDescriptorInfoFunc(const uint8_t* data, size_t size) void AlignmentFunc(const uint8_t* data, size_t size) { - std::ifstream inputFile(UNSIGNED_HAP_FILE_PATH, std::ios::binary); + std::string name(reinterpret_cast(data), size); + std::ifstream inputFile(UNSIGNED_HAP_FILE_PATH + name, std::ios::binary); auto zip = std::make_shared(); int aliBytes = 102400; if (!zip->Init(inputFile)) { @@ -162,7 +165,8 @@ void AlignmentFunc(const uint8_t* data, size_t size) void EndOfCentralDirectoryInfoFunc(const uint8_t* data, size_t size) { - std::ifstream inputFile(UNSIGNED_HAP_FILE_PATH, std::ios::binary); + std::string name(reinterpret_cast(data), size); + std::ifstream inputFile(UNSIGNED_HAP_FILE_PATH + name, std::ios::binary); auto zip = std::make_shared(); if (!zip->Init(inputFile)) { return;