Applied sizeof operator on fixed sized array to calculate size.
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertManager.cpp
index eb0e3d1..d2d97f5 100644 (file)
@@ -383,7 +383,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                        int len = strlen(pSigAlg);
                        if (len <= _MAX_CERT_ALGORITHM_SIZE)
                        {
-                               strncpy(pCertInfo->sigAlgorithm, pSigAlg, len);
+                               snprintf(pCertInfo->sigAlgorithm, sizeof(pCertInfo->sigAlgorithm), "%s", pSigAlg);
                        }
                        else
                        {
@@ -421,7 +421,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                memset(pCertInfo->subjectName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
                if (subLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
                {
-                       strncpy(pCertInfo->subjectName, reinterpret_cast< const char* >(pSubjectName), subLen);
+                       snprintf(pCertInfo->subjectName, sizeof(pCertInfo->subjectName), "%s", reinterpret_cast< const char* >(pSubjectName));
                }
                ParseCertTitle(reinterpret_cast< char* >(pSubjectName), pCertInfo->certTitle);
                ClearLastResult();
@@ -433,7 +433,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                memset(pCertInfo->issuerName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
                if (issuerLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
                {
-                       strncpy(pCertInfo->issuerName, reinterpret_cast< const char* >(pIssuerName), issuerLen);
+                       snprintf(pCertInfo->issuerName, sizeof(pCertInfo->issuerName), "%s", reinterpret_cast< const char* >(pIssuerName));
                }
                ParseCertTitle(reinterpret_cast< char* >(pIssuerName), pCertInfo->certSubTitle);
                ClearLastResult();
@@ -762,8 +762,8 @@ _CertManager::GetCertificateType(CertificateHandle certHandle, _CaCertType* pCer
        SysTryReturnResult(NID_SEC_CERT, lenSubjectName > 0, E_SYSTEM, "Subject length is not valid.");
        SysTryReturnResult(NID_SEC_CERT, lenIssuerName > 0, E_SYSTEM, "Issuer length is not valid.");
 
-       strncpy(subjectName, reinterpret_cast< const char* >(pTbsCert->GetSubjectName()), lenSubjectName);
-       strncpy(issuerName, reinterpret_cast< const char* >(pTbsCert->GetIssuerName()), lenIssuerName);
+       snprintf(subjectName, sizeof(subjectName), "%s", reinterpret_cast< const char* >(pTbsCert->GetSubjectName()));
+       snprintf(issuerName, sizeof(issuerName), "%s", reinterpret_cast< const char* >(pTbsCert->GetIssuerName()));
 
        pCertDb = _CertDbManager::GetInstance();
        SysTryReturnResult(NID_SEC_CERT, pCertDb != null, E_SYSTEM, "Failed to get instance of certificate database manager.");
@@ -794,7 +794,7 @@ _CertManager::ParseCertTitle(char subject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1], ch
        char* pSubStr = null;
        char tempSubject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1] = {0, };
 
-       strncpy(tempSubject, subject, strlen(subject + 1));
+       snprintf(tempSubject, sizeof(tempSubject), "%s", subject);
        pPivotPtr = tempSubject;
        for (;; pSubStr = null)
        {
@@ -1107,7 +1107,7 @@ _CertManager::OpenUserCertificateStore(int& totalCount)
 
        totalCount = 0;
 
-       snprintf(condition, _MAX_TYPE_CONST_SIZE, "installed = '%s'", installedRecord);
+       snprintf(condition, sizeof(condition), "installed = '%s'", installedRecord);
 
        std::unique_ptr< _UserCertDbStore > pUserCertDbStore(new (std::nothrow) _UserCertDbStore());
        SysTryReturn(NID_SEC_CERT, pUserCertDbStore != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
@@ -1185,7 +1185,7 @@ _CertManager::OpenRootCaStore(_CaCertType type, int& totalCount) // _CERT_TYPE_T
        SysTryReturn(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
        SysTryReturn(NID_SEC_CERT, type < _CERT_TYPE_MAX, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
 
-       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
+       snprintf(condition, sizeof(condition), "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
 
        std::unique_ptr< _CaCertDbStore > pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
        SysTryReturn(NID_SEC_CERT, pCaCertDbStore != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
@@ -1256,7 +1256,7 @@ _CertManager::CheckRootCaIntegrity(void)
 
        ClearLastResult();
 
-       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", _CERT_TYPE_ROOT_CA, installedRecord);
+       snprintf(condition, sizeof(condition), "certType = %d and installed = '%s'", _CERT_TYPE_ROOT_CA, installedRecord);
 
        std::unique_ptr< _CaCertDbStore > pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
        SysTryReturnResult(NID_SEC_CERT, pCaCertDbStore != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");