Fix SVACE: AUTO_CAUSES_COPY detect 29/324829/2
authorLe <xuan.tien@samsung.com>
Tue, 27 May 2025 11:05:23 +0000 (18:05 +0700)
committerLe <xuan.tien@samsung.com>
Tue, 27 May 2025 12:26:11 +0000 (19:26 +0700)
Change-Id: I4a289000abac79d06b542bd1789fb5500110c3a2
Signed-off-by: Le <xuan.tien@samsung.com>
examples/signature-validator-since-4.0.cpp
tests/capi/test-certificate.cpp
tests/vcore/test-signature-validator.cpp
unit-tests/test_cert_server_logic.cpp
unit-tests/test_vcore_api_cert.cpp
unit-tests/test_vcore_api_pkcs12.cpp

index 8c4050fd00869365b8d5f3bd37140327b1f0f7a2..2be09dc0f82e034d4cf85fdc7939b328febb88b0 100644 (file)
@@ -63,15 +63,15 @@ int main()
                }
 
                // Step 2. Get certificate list from signature.
-               auto authorSigData = sigDataMap[ValidationCore::SignatureType::AUTHOR];
+               const auto& authorSigData = sigDataMap[ValidationCore::SignatureType::AUTHOR];
                for (const auto &certPtr : authorSigData.getCertList())
                        std::cout << "Author certificate > " << certPtr->getBase64() << std::endl;
 
-               auto dist1SigData = sigDataMap[ValidationCore::SignatureType::DISTRIBUTOR1];
+               const auto& dist1SigData = sigDataMap[ValidationCore::SignatureType::DISTRIBUTOR1];
                for (const auto &certPtr : dist1SigData.getCertList())
                        std::cout << "Distributor1 certificate > " << certPtr->getBase64() << std::endl;
 
-               auto dist2SigData = sigDataMap[ValidationCore::SignatureType::DISTRIBUTOR2];
+               const auto& dist2SigData = sigDataMap[ValidationCore::SignatureType::DISTRIBUTOR2];
                for (const auto &certPtr : dist2SigData.getCertList())
                        std::cout << "Distributor2 certificate > " << certPtr->getBase64() << std::endl;
 
index a1944c29466f240d3a01a6c5589bff22af3d0f5b..87d1ef9750810fc76bf3e83651c12a22ac6741cf 100644 (file)
@@ -511,7 +511,7 @@ RUNNER_TEST(T0206_certificate_get_visibility)
                                                CERTSVC_VISIBILITY_PARTNER,
                                                TestData::certCAPartner));
 
-       for (auto ca : caMap) {
+       for (const auto& ca : caMap) {
                CertSvcInstance instance;
                CertSvcCertificate certificate;
                int retval;
index b5206096f7ca0561170dc1af5973698b18df9e57..2b6a6c747ed6d46e7d789acc6682c68931151f08 100644 (file)
@@ -42,7 +42,7 @@ std::vector<RetPair> runCheck(const std::string &contentPath,
                "SignatureFinder failed");
 
        std::vector<RetPair> ret;
-       for (auto &sig : signatureSet) {
+       for (const auto &sig : signatureSet) {
                SignatureValidator validator(sig);
                SignatureData outData;
                ret.push_back(std::make_pair(validator.check(contentPath,
@@ -126,7 +126,7 @@ RUNNER_TEST(T00102_positive_public_check_ref)
                RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
                                                  "sig validation should be success: " << ret.first);
 
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(sigData.getVisibilityLevel() == CertStoreId::VIS_PUBLIC,
                                                          "visibility check failed.");
@@ -144,7 +144,7 @@ RUNNER_TEST(T00103_positive_partner_check_ref)
                RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
                                                  "sig validation should be success: " << ret.first);
 
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(sigData.getVisibilityLevel() == CertStoreId::VIS_PARTNER,
                                                          "visibility check failed.");
@@ -161,7 +161,7 @@ RUNNER_TEST(T00104_positive_public_uncheck_ref)
                RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
                                                  "sig validation should be success: " << ret.first);
 
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(sigData.getVisibilityLevel() == CertStoreId::VIS_PUBLIC,
                                                          "visibility check failed.");
@@ -179,7 +179,7 @@ RUNNER_TEST(T00105_positive_partner_uncheck_ref)
                RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
                                                  "sig validation should be success: " << ret.first);
 
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(sigData.getVisibilityLevel() == CertStoreId::VIS_PARTNER,
                                                          "visibility check failed.");
@@ -227,7 +227,7 @@ RUNNER_TEST(T00108_distributor_disregard_check)
                                                          true);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.isAuthorSignature())
                        RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_CHAIN,
                                                          "author sig validation should be fail : "
@@ -254,7 +254,7 @@ RUNNER_TEST(T00109_positive_platform_check_ref)
                RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
                                                  "sig validation should be success: " << ret.first);
 
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(sigData.getVisibilityLevel() == CertStoreId::VIS_PLATFORM,
                                                          "visibility check failed.");
@@ -272,7 +272,7 @@ RUNNER_TEST(T00110_positive_platform_uncheck_ref)
                RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
                                                  "sig validation should be success: " << ret.first);
 
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(sigData.getVisibilityLevel() == CertStoreId::VIS_PLATFORM,
                                                          "visibility check failed.");
@@ -286,7 +286,7 @@ RUNNER_TEST(T00111_positive_wgt_link)
                                                          true);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                // this condition is for OCSP Success in signature1.xml
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(ret.first == E_SIG_NONE,
@@ -303,7 +303,7 @@ RUNNER_TEST(T00112_negative_wgt_link)
                                                          true);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                        RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_REF,
                                                          "If DT_LNK type point outside of package, "
@@ -319,7 +319,7 @@ RUNNER_TEST(T00151_negative_hash_check_ref)
                                                          true);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                                RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_SIG,
                                                                  "dist sig shouldn't be success: "
@@ -334,7 +334,7 @@ RUNNER_TEST(T00152_negative_hash_uncheck_ref)
                                                          false);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                                RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_SIG,
                                                                  "dist sig shouldn't be success: "
@@ -349,7 +349,7 @@ RUNNER_TEST(T00153_negative_signature_check_ref)
                                                          true);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                                RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_SIG,
                                                                  "dist sig shouldn't be success: "
@@ -364,7 +364,7 @@ RUNNER_TEST(T00154_negative_signature_uncheck_ref)
                                                          false);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                                RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_SIG,
                                                                  "dist sig shouldn't be success: "
@@ -379,7 +379,7 @@ RUNNER_TEST(T00155_negative_tpk_with_added_malfile)
                                                          true);
 
        for (const auto &ret : retVector) {
-               auto sigData = ret.second;
+               const auto& sigData = ret.second;
                if (sigData.getSignatureNumber() == 1)
                                RUNNER_ASSERT_MSG(ret.first == E_SIG_INVALID_REF,
                                                                  "dist sig shouldn't be success: "
index af91da9650d394e9dd8b9481b7015ce1d939534d..7fd49660df92a7baaf8c3c9a0055acd3a1c20aa7 100644 (file)
@@ -141,7 +141,7 @@ void installCertToStore(
        CertType certType)
 {
        int result;
-       for(auto storeType: storeTypeMap)
+       for(const auto& storeType: storeTypeMap)
        {
                result = installCertificateToStore(
                        storeType.second,
@@ -159,7 +159,7 @@ void installCertToStore(
 void uninstallCertFromStore()
 {
        int result;
-       for(auto storeType: storeTypeMap)
+       for(const auto& storeType: storeTypeMap)
        {
                result = deleteCertificateFromStore(storeType.second, gNamePrefix.c_str());
                BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
@@ -181,7 +181,7 @@ void setCertificateStatusToStoreWithSystemStore()
 void setCertStatusToStore(CertStatus certStatus)
 {
        int result;
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM.c_str(), PEM_CRT);
 
@@ -198,7 +198,7 @@ void setCertStatusToStore(CertStatus certStatus)
 void getCertStatusFromStore(int expectedResult, CertStatus expectedStatus, bool isInstallCert)
 {
        int result;
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                CertStatus status = DISABLED;
                if (isInstallCert)
@@ -220,7 +220,7 @@ void checkAliasExistsAtStore(int expectedResult, int expectedUnique, std::string
                installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM.c_str(), PEM_CRT);
 
        int unique = 0, result;
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                result = checkAliasExistsInStore(storeType.second, alias.empty() ? NULL : alias.c_str(), &unique);
 
@@ -239,7 +239,7 @@ void getCertAliasFromStore(int expectedResult, std::string expectedAlias, int al
 
        char alias[VCORE_MAX_RECV_DATA_SIZE];
        int result;
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                result = getCertificateAliasFromStore(storeType.second, gNamePrefix.c_str(), alias, aliasSize);
 
@@ -405,7 +405,7 @@ NEGATIVE_TEST_CASE(T_get_certificate_status_from_store_with_no_records)
 NEGATIVE_TEST_CASE(T_get_certificate_status_from_store_with_gname_param_null_and_db_no_init)
 {
        int result;
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                result = getCertificateStatusFromStore(storeType.second, NULL, NULL);
                BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
@@ -435,7 +435,7 @@ NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_database_no_records)
        int result = initialize_db();
        BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
 
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                result = setCertificateStatusToStore(storeType.second, DISABLED, systemGname.c_str(), ENABLED);
                BOOST_CHECK_EQUAL(result, CERTSVC_FAIL);
@@ -458,7 +458,7 @@ NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_database_no_init_and_g
        int result = setCertificateStatusToStore(SYSTEM_STORE, DISABLED, systemGname.c_str(), ENABLED);
        BOOST_CHECK_EQUAL(result, CERTSVC_FAIL);
 
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                result = setCertificateStatusToStore(storeType.second, ENABLED, NULL, ENABLED);
                BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
@@ -469,7 +469,7 @@ NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_status_parameter_inval
 {
        CertStatus outOfCertStatus = static_cast<CertStatus>(1 << 2);
        int result;
-       for (auto storeType : storeTypeMap)
+       for (const auto& storeType : storeTypeMap)
        {
                result = setCertificateStatusToStore(storeType.second, ENABLED, systemGname.c_str(), outOfCertStatus);
                BOOST_CHECK_EQUAL(result, CERTSVC_INVALID_STATUS);
@@ -504,7 +504,7 @@ POSITIVE_TEST_CASE(T_install_certificate_to_store)
        result = initialize_db();
        BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
 
-       for(auto storeType: storeTypeMap)
+       for(const auto& storeType: storeTypeMap)
        {
                gName = gNamePrefix + storeType.first + std::to_string(PEM_CRT);
                commonName = commonNamePrefix + storeType.first + std::to_string(PEM_CRT);
@@ -567,7 +567,7 @@ NEGATIVE_TEST_CASE(T_install_certificate_to_store)
        result = initialize_db();
        BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
 
-       for(auto storeType: storeTypeMap)
+       for(const auto& storeType: storeTypeMap)
        {
                gName = gNamePrefix + storeType.first + std::to_string(PEM_CRT);
                commonName = commonNamePrefix + storeType.first + std::to_string(PEM_CRT);
@@ -739,7 +739,7 @@ POSITIVE_TEST_CASE(T_load_certificate_from_store)
        result = initialize_db();
        BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
 
-       for (auto storeType: storeTypeMap)
+       for (const auto& storeType: storeTypeMap)
        {
                const std::string gnameEndUser =
                        gNamePrefix + storeType.first + std::to_string(P12_END_USER);
@@ -813,7 +813,7 @@ POSITIVE_TEST_CASE(T_delete_certificate_from_store)
 
        std::string gnamePem, gnameEndUser, gnameIntermediate;
 
-       for(auto storeType: storeTypeMap)
+       for(const auto& storeType: storeTypeMap)
        {
                gnamePem = gNamePrefix + storeType.first + std::to_string(PEM_CRT);
                gnameEndUser = gNamePrefix + storeType.first + std::to_string(P12_END_USER);
index b1cca5f0d78970dbe95463b912ae1762b33924ba..53d5cf65d036399c9d2917c51582808cf2e10c92 100644 (file)
@@ -942,7 +942,7 @@ POSITIVE_TEST_CASE(T_certsvc_certificate_get_visibility)
                CERTSVC_VISIBILITY_PARTNER,
                CertCA::Partner));
 
-       for (auto ca : caMap) {
+       for (const auto& ca : caMap) {
                CertSvcCertificate certificate;
                int result;
                CertSvcVisibility visibility;
index cba0dc62e15d2aca50a694dcf616c5a26b3b74f7..5965da0cc079a1bab1cbe00198cfb4bf4f1fcf1b 100644 (file)
@@ -401,7 +401,7 @@ POSITIVE_TEST_CASE(T_import_cert_from_to_individual_store)
 
        BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
 
-       for (auto storeType: storeTypeMap)
+       for (const auto& storeType: storeTypeMap)
        {
                path = ServerCert::PemWithoutPassPath;
                alias = PemPrefix + storeType.first + std::to_string(PEM_CRT);
@@ -520,7 +520,7 @@ POSITIVE_TEST_CASE(T_certsvc_pkcs12_import_from_file_to_store_ret_list)
 
        BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
 
-       for (auto storeType: storeTypeMap)
+       for (const auto& storeType: storeTypeMap)
        {
                path = ServerCert::P12WithoutPassPath;
                alias = P12Prefix + RetList + storeType.first + std::to_string(P12_END_USER);
@@ -614,7 +614,7 @@ POSITIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_list_from_stores)
        getCertListFromStoreAndFree(ALL_STORE, DISABLED, CERTSVC_SUCCESS);
        getCertListFromStoreAndFree(ALL_STORE, ENABLED, CERTSVC_SUCCESS);
 
-       for (auto storeType: storeTypeMap)
+       for (const auto& storeType: storeTypeMap)
        {
                getCertListFromStoreAndFree(storeType.second, DISABLED, CERTSVC_SUCCESS);
                getCertListFromStoreAndFree(storeType.second, ENABLED, CERTSVC_SUCCESS);
@@ -1149,7 +1149,7 @@ POSITIVE_TEST_CASE(T_certsvc_pkcs12_delete_certificate_from_store)
 
        BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
 
-       for (auto storeType: storeTypeMap)
+       for (const auto& storeType: storeTypeMap)
        {
                CertSvcStoreCertList *certList = NULL;
                size_t length = 0;