IOT-1835 Make resource/csdk/security W4 compliant.
authorAlex Kelley <alexke@microsoft.com>
Wed, 15 Feb 2017 23:50:32 +0000 (15:50 -0800)
committerKevin Kane <kkane@microsoft.com>
Tue, 28 Feb 2017 02:15:05 +0000 (02:15 +0000)
These changes include the following:
- Prepare resource/csdk/security/SConscript to enable /W4.
- Fix W4 warnings under resource/csdk/security/src
- Fix W4 warnings under resource/csdk/security/tool

Changes to resource/csdk/security/provisioning will come in another review.

Change-Id: I3a26fa952103b3b218569155cd1341aa696944e1
Signed-off-by: Alex Kelley <alexke@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17399
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
17 files changed:
resource/csdk/security/SConscript
resource/csdk/security/src/aclresource.c
resource/csdk/security/src/amaclresource.c
resource/csdk/security/src/credresource.c
resource/csdk/security/src/crlresource.c
resource/csdk/security/src/directpairing.c
resource/csdk/security/src/doxmresource.c
resource/csdk/security/src/dpairingresource.c
resource/csdk/security/src/oxmpincommon.c
resource/csdk/security/src/pconfresource.c
resource/csdk/security/src/pstatresource.c
resource/csdk/security/src/secureresourcemanager.c
resource/csdk/security/src/srmresourcestrings.c
resource/csdk/security/src/strptime.c
resource/csdk/security/src/svcresource.c
resource/csdk/security/src/verresource.c
resource/csdk/security/tool/json2cbor.c

index 825321d..398b0a4 100644 (file)
@@ -59,6 +59,14 @@ libocsrm_env.PrependUnique(CPPPATH = [
 
 if target_os in ['windows', 'msys_nt']:
        libocsrm_env.AppendUnique(LIBPATH = [os.path.join(libocsrm_env.get('BUILD_DIR'), 'resource', 'oc_logger')])
+    # Enable W4 but disable the following warnings:
+    #  - warning C4201: nonstandard extension used: nameless struct/union
+    #    - Disabled due to the widespread usage in internal IoTivity components as well as external libs.
+    #  - warning C4232: nonstandard extension used: 'read': address of dllimport 'fread' is not static, identity not guaranteed
+    #    - fread, frwrite, etc are provided by the platform and cannot be changed.
+       # libocsrm_env.AppendUnique(CCFLAGS=['/wd4201', '/wd4232', '/W4', '/WX'])
+    # Leave /W3 /WX enabled until IOT-1835 and IOT-1836 are merged. This is to prevent build breaks and possible /W3 issues from
+    # being merged while the different pieces of the update to /W4 are under review and being merged.
        libocsrm_env.AppendUnique(CCFLAGS=['/W3', '/WX'])
 
 if target_os in ['linux', 'android', 'tizen', 'msys_nt', 'windows'] and libocsrm_env.get('SECURED') == '1':
index 83c0a51..d3f141d 100644 (file)
@@ -160,7 +160,6 @@ void DeleteACLList(OicSecAcl_t* acl)
 OicSecAce_t* DuplicateACE(const OicSecAce_t* ace)
 {
     OicSecAce_t* newAce = NULL;
-    size_t allocateSize = 0;
 
     if(ace)
     {
@@ -312,7 +311,8 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz
     }
 
     outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     // Create ACL Map (aclist, rownerid)
@@ -724,11 +724,11 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
                     while (cbor_value_is_valid(&aceMap))
                     {
                         char* name = NULL;
-                        size_t len = 0;
-                        CborType type = cbor_value_get_type(&aceMap);
-                        if (type == CborTextStringType)
+                        size_t tempLen = 0;
+                        CborType aceMapType = cbor_value_get_type(&aceMap);
+                        if (aceMapType == CborTextStringType)
                         {
-                            cborFindResult = cbor_value_dup_text_string(&aceMap, &name, &len, NULL);
+                            cborFindResult = cbor_value_dup_text_string(&aceMap, &name, &tempLen, NULL);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in ACE Map.");
                             cborFindResult = cbor_value_advance(&aceMap);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Value in ACE Map.");
@@ -739,7 +739,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
                             if (strcmp(name, OIC_JSON_SUBJECTID_NAME)  == 0)
                             {
                                 char *subject = NULL;
-                                cborFindResult = cbor_value_dup_text_string(&aceMap, &subject, &len, NULL);
+                                cborFindResult = cbor_value_dup_text_string(&aceMap, &subject, &tempLen, NULL);
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding subject Value.");
                                 if(strcmp(subject, WILDCARD_RESOURCE_URI) == 0)
                                 {
@@ -784,7 +784,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
                                         // "href"
                                         if (0 == strcmp(OIC_JSON_HREF_NAME, rMapName))
                                         {
-                                            cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->href, &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->href, &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Href Value.");
                                         }
 
@@ -839,7 +839,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
                                         // "rel"
                                         if (0 == strcmp(OIC_JSON_REL_NAME, rMapName))
                                         {
-                                            cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->rel, &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->rel, &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding REL Value.");
                                         }
 
@@ -892,8 +892,8 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
                                     cborFindResult = cbor_value_enter_container(&validitiesMap, &validityMap);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding a validity Map.");
 
-                                    size_t len = 0;
-                                    cborFindResult =cbor_value_dup_text_string(&validityMap, &validity->period, &len, NULL);
+                                    size_t vmLen = 0;
+                                    cborFindResult = cbor_value_dup_text_string(&validityMap, &validity->period, &vmLen, NULL);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding a Period value.");
 
                                     //recurrence (string array)
@@ -909,7 +909,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
 
                                     for(size_t i = 0; cbor_value_is_text_string(&recurrenceMap) && i < validity->recurrenceLen; i++)
                                     {
-                                        cborFindResult = cbor_value_dup_text_string(&recurrenceMap, &validity->recurrences[i], &len, NULL);
+                                        cborFindResult = cbor_value_dup_text_string(&recurrenceMap, &validity->recurrences[i], &vmLen, NULL);
                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding a recurrence Value.");
 
                                         cborFindResult = cbor_value_advance(&recurrenceMap);
@@ -923,7 +923,7 @@ OicSecAcl_t* CBORPayloadToAcl2(const uint8_t *cborPayload, const size_t size)
                             OICFree(name);
                         }
 
-                        if (type != CborMapType && cbor_value_is_valid(&aceMap))
+                        if (aceMapType != CborMapType && cbor_value_is_valid(&aceMap))
                         {
                             cborFindResult = cbor_value_advance(&aceMap);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing the Array.");
@@ -1052,11 +1052,11 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                 while (cbor_value_is_valid(&aceMap))
                                 {
                                     char* name = NULL;
-                                    size_t len = 0;
-                                    CborType type = cbor_value_get_type(&aceMap);
-                                    if (type == CborTextStringType)
+                                    size_t tempLen = 0;
+                                    CborType aceMapType = cbor_value_get_type(&aceMap);
+                                    if (aceMapType == CborTextStringType)
                                     {
-                                        cborFindResult = cbor_value_dup_text_string(&aceMap, &name, &len, NULL);
+                                        cborFindResult = cbor_value_dup_text_string(&aceMap, &name, &tempLen, NULL);
                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in ACE Map.");
                                         cborFindResult = cbor_value_advance(&aceMap);
                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Value in ACE Map.");
@@ -1067,7 +1067,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                         if (strcmp(name, OIC_JSON_SUBJECTID_NAME)  == 0)
                                         {
                                             char *subject = NULL;
-                                            cborFindResult = cbor_value_dup_text_string(&aceMap, &subject, &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&aceMap, &subject, &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding subject Value.");
                                             if(strcmp(subject, WILDCARD_RESOURCE_URI) == 0)
                                             {
@@ -1111,7 +1111,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                                     // "href"
                                                     if (0 == strcmp(OIC_JSON_HREF_NAME, rMapName))
                                                     {
-                                                        cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->href, &len, NULL);
+                                                        cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->href, &tempLen, NULL);
                                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Href Value.");
                                                     }
 
@@ -1164,7 +1164,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                                     // "rel"
                                                     if (0 == strcmp(OIC_JSON_REL_NAME, rMapName))
                                                     {
-                                                        cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->rel, &len, NULL);
+                                                        cborFindResult = cbor_value_dup_text_string(&rMap, &rsrc->rel, &tempLen, NULL);
                                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding REL Value.");
                                                     }
 
@@ -1217,8 +1217,8 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                                 cborFindResult = cbor_value_enter_container(&validitiesMap, &validityMap);
                                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding a validity Map.");
 
-                                                size_t len = 0;
-                                                cborFindResult =cbor_value_dup_text_string(&validityMap, &validity->period, &len, NULL);
+                                                size_t vmLen = 0;
+                                                cborFindResult =cbor_value_dup_text_string(&validityMap, &validity->period, &vmLen, NULL);
                                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding a Period value.");
 
                                                 //recurrence (string array)
@@ -1234,7 +1234,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
 
                                                 for(size_t i = 0; cbor_value_is_text_string(&recurrenceMap) && i < validity->recurrenceLen; i++)
                                                 {
-                                                    cborFindResult = cbor_value_dup_text_string(&recurrenceMap, &validity->recurrences[i], &len, NULL);
+                                                    cborFindResult = cbor_value_dup_text_string(&recurrenceMap, &validity->recurrences[i], &vmLen, NULL);
                                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding a recurrence Value.");
 
                                                     cborFindResult = cbor_value_advance(&recurrenceMap);
@@ -1251,7 +1251,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                         if (strcmp(name, OIC_JSON_EOWNERID_NAME)  == 0)
                                         {
                                             char *eowner = NULL;
-                                            cborFindResult = cbor_value_dup_text_string(&aceMap, &eowner, &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&aceMap, &eowner, &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding eownerId Value.");
                                             if(NULL == ace->eownerID)
                                             {
@@ -1266,7 +1266,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size)
                                         OICFree(name);
                                     }
 
-                                    if (type != CborMapType && cbor_value_is_valid(&aceMap))
+                                    if (aceMapType != CborMapType && cbor_value_is_valid(&aceMap))
                                     {
                                         cborFindResult = cbor_value_advance(&aceMap);
                                         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing the Array.");
@@ -1378,7 +1378,7 @@ exit:
  *     ::OC_STACK_NO_RESOURCE on failure to find the appropriate ACE
  *     ::OC_STACK_INVALID_PARAM on invalid parameter
  */
-OCStackResult RemoveACE(const OicUuid_t * subject, const char * resource)
+OCStackResult RemoveACE(const OicUuid_t *subject, const char *resource)
 {
     OIC_LOG(DEBUG, TAG, "IN RemoveACE");
 
@@ -1387,7 +1387,7 @@ OCStackResult RemoveACE(const OicUuid_t * subject, const char * resource)
     bool deleteFlag = false;
     OCStackResult ret = OC_STACK_NO_RESOURCE;
 
-    if (memcmp(subject->id, &WILDCARD_SUBJECT_ID, sizeof(subject->id)) == 0)
+    if (memcmp(subject, &WILDCARD_SUBJECT_ID, sizeof(*subject)) == 0)
     {
         OIC_LOG_V(ERROR, TAG, "%s received invalid parameter", __func__ );
         return  OC_STACK_INVALID_PARAM;
@@ -1860,7 +1860,9 @@ static OCEntityHandlerResult HandleACLGetRequest(const OCEntityHandlerRequest *e
          * Below code needs to be updated for scenarios when Subject have
          * multiple ACE's in ACL resource.
          */
-        while ((currentAce = GetACLResourceData(&subject, &savePtr)))
+        for (currentAce = GetACLResourceData(&subject, &savePtr);
+             NULL != currentAce;
+             currentAce = GetACLResourceData(&subject, &savePtr))
         {
             targetAcl.aces = (OicSecAce_t*)currentAce;
 
@@ -1873,7 +1875,7 @@ static OCEntityHandlerResult HandleACLGetRequest(const OCEntityHandlerRequest *e
                 OicSecRsrc_t *rsrc = NULL;
                 LL_FOREACH(currentAce->resources, rsrc)
                 {
-                    if(0 == strcmp(rsrc->href, resource) ||
+                    if (0 == strcmp(rsrc->href, resource) ||
                         0 == strcmp(WILDCARD_RESOURCE_URI, rsrc->href))
                     {
                         // Convert ACL data into CBOR format for transmission
@@ -1978,12 +1980,12 @@ static OCEntityHandlerResult HandleACLPostRequest(const OCEntityHandlerRequest *
 
             if(OC_EH_OK == ehRet)
             {
-                size_t size = 0;
+                size_t cborSize = 0;
                 uint8_t *cborPayload = NULL;
 
-                if (OC_STACK_OK == AclToCBORPayload(gAcl, &cborPayload, &size))
+                if (OC_STACK_OK == AclToCBORPayload(gAcl, &cborPayload, &cborSize))
                 {
-                    if (UpdateSecureResourceInPS(OIC_JSON_ACL_NAME, cborPayload, size) == OC_STACK_OK)
+                    if (UpdateSecureResourceInPS(OIC_JSON_ACL_NAME, cborPayload, cborSize) == OC_STACK_OK)
                     {
                         ehRet = OC_EH_CHANGED;
                     }
@@ -2123,7 +2125,6 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl)
     OicSecRsrc_t* resRsrc = NULL;
     OicSecRsrc_t* deviceRsrc = NULL;
     OicSecRsrc_t* platformRsrc = NULL;
-    OicSecRsrc_t* aclRsrc = NULL;
     OicSecRsrc_t* doxmRsrc = NULL;
     OicSecRsrc_t* pstatRsrc = NULL;
 
@@ -2147,7 +2148,7 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl)
     VERIFY_NOT_NULL(TAG, readOnlyAce, ERROR);
 
     // Subject -- Mandatory
-    memcpy(readOnlyAce->subjectuuid.id, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t));
+    memcpy(&readOnlyAce->subjectuuid, &WILDCARD_SUBJECT_ID, sizeof(readOnlyAce->subjectuuid));
 
     // Resources -- Mandatory
     // /oic/res
@@ -2219,7 +2220,7 @@ OCStackResult GetDefaultACL(OicSecAcl_t** defaultAcl)
     VERIFY_NOT_NULL(TAG, readWriteAce, ERROR);
 
     // Subject -- Mandatory
-    memcpy(readWriteAce->subjectuuid.id, &WILDCARD_SUBJECT_ID, sizeof(OicUuid_t));
+    memcpy(&readWriteAce->subjectuuid, &WILDCARD_SUBJECT_ID, sizeof(readWriteAce->subjectuuid));
 
     // Resources -- Mandatory
     // /oic/sec/doxm
@@ -2635,8 +2636,20 @@ static OicSecAce_t* GetSecDefaultACE()
     const int NUM_OF_DOXM_IF  = 1;
     const int NUM_OF_PSTAT_RT = 1;
     const int NUM_OF_PSTAT_IF = 1;
+
+#ifdef _MSC_VER
+    // OIC_RSRC_TYPE_SEC_DOXM and OIC_RSRC_TYPE_SEC_PSTAT are const but also extern so they cause warnings.
+#pragma warning(push)
+#pragma warning(disable:4204)
+#endif
+
     const char *doxmRt[] = { OIC_RSRC_TYPE_SEC_DOXM };
     const char *pstatRt[] = { OIC_RSRC_TYPE_SEC_PSTAT };
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
     const char *doxmIf[] = { OC_RSRVD_INTERFACE_DEFAULT };
     const char *pstatIf[] = { OC_RSRVD_INTERFACE_DEFAULT };
     OicSecRsrc_t* doxmRsrc = NULL;
@@ -2647,7 +2660,7 @@ static OicSecAce_t* GetSecDefaultACE()
     VERIFY_NOT_NULL(TAG, newAce, ERROR);
 
     // Subject -- Mandatory
-    memcpy(newAce->subjectuuid.id, &WILDCARD_SUBJECT_ID, WILDCARD_SUBJECT_ID_LEN);
+    memcpy(&newAce->subjectuuid, &WILDCARD_SUBJECT_ID, WILDCARD_SUBJECT_ID_LEN);
 
     //Resources -- Mandatory
     //Add doxm
index 6eac57c..82e94e4 100644 (file)
@@ -73,8 +73,7 @@ void DeleteAmaclList(OicSecAmacl_t* amacl)
     }
 }
 
-OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayload,
-                                 size_t *cborSize)
+OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayload, size_t *cborSize)
 {
     if (NULL == amaclS || NULL == cborPayload || NULL != *cborPayload || NULL == cborSize)
     {
@@ -101,7 +100,8 @@ OCStackResult AmaclToCBORPayload(const OicSecAmacl_t *amaclS, uint8_t **cborPayl
 
     const OicSecAmacl_t *amacl = amaclS;
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     // Create AMACL Map
@@ -470,12 +470,12 @@ static OCEntityHandlerResult HandleAmaclPostRequest (const OCEntityHandlerReques
         {
             // Append the new Amacl to existing Amacl
             LL_APPEND(gAmacl, newAmacl);
-            size_t size = 0;
+            size_t cborSize = 0;
             // Convert Amacl data into JSON for update to persistent storage.
             uint8_t *cborPayload = NULL;
-            res = AmaclToCBORPayload(gAmacl, &cborPayload, &size);
+            res = AmaclToCBORPayload(gAmacl, &cborPayload, &cborSize);
             if (cborPayload && (OC_STACK_OK == res) &&
-                (OC_STACK_OK == UpdateSecureResourceInPS(OIC_JSON_AMACL_NAME, cborPayload, size)))
+                (OC_STACK_OK == UpdateSecureResourceInPS(OIC_JSON_AMACL_NAME, cborPayload, cborSize)))
             {
                 ehRet = OC_EH_RESOURCE_CREATED;
             }
index ada892a..50e6c93 100644 (file)
@@ -370,8 +370,8 @@ static CborError SerializeEncodingToCborInternal(CborEncoder *map, const OicSecK
     }
     else
     {
-        OIC_LOG(ERROR, TAG, "Unknown encoding type.");
-        VERIFY_CBOR_SUCCESS(TAG, CborErrorUnknownType, "Failed Adding Encoding Value.");
+        OIC_LOG_V(ERROR, TAG, "Unknown encoding type: %u.", value->encoding);
+        return CborErrorUnknownType;
     }
     exit:
     return cborEncoderResult;
@@ -600,7 +600,8 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload
     }
 
     outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     // Create CRED Root Map (creds, rownerid)
@@ -888,7 +889,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
             if (strcmp(tagName, OIC_JSON_CREDS_NAME)  == 0)
             {
                 // Enter CREDS Array
-                size_t len = 0;
+                size_t tempLen = 0;
                 int credCount = 0;
                 CborValue credArray = { .parser = NULL, .ptr = NULL, .remaining = 0, .extra = 0, .type = 0, .flags = 0 };
                 cborFindResult = cbor_value_enter_container(&CredRootMap, &credArray);
@@ -923,10 +924,10 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                     while(cbor_value_is_valid(&credMap) && cbor_value_is_text_string(&credMap))
                     {
                         char* name = NULL;
-                        CborType type = cbor_value_get_type(&credMap);
-                        if (type == CborTextStringType)
+                        CborType cmType = cbor_value_get_type(&credMap);
+                        if (cmType == CborTextStringType)
                         {
-                            cborFindResult = cbor_value_dup_text_string(&credMap, &name, &len, NULL);
+                            cborFindResult = cbor_value_dup_text_string(&credMap, &name, &tempLen, NULL);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Name in CRED Map.");
                             cborFindResult = cbor_value_advance(&credMap);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing Value in CRED Map.");
@@ -945,7 +946,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                             if (strcmp(name, OIC_JSON_SUBJECTID_NAME)  == 0)
                             {
                                 char *subjectid = NULL;
-                                cborFindResult = cbor_value_dup_text_string(&credMap, &subjectid, &len, NULL);
+                                cborFindResult = cbor_value_dup_text_string(&credMap, &subjectid, &tempLen, NULL);
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding subjectid Value.");
                                 if(strcmp(subjectid, WILDCARD_RESOURCE_URI) == 0)
                                 {
@@ -998,14 +999,14 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                             //Credusage -- Not Mandatory
                             if (0 == strcmp(OIC_JSON_CREDUSAGE_NAME, name))
                             {
-                                cborFindResult = cbor_value_dup_text_string(&credMap, &cred->credUsage, &len, NULL);
+                                cborFindResult = cbor_value_dup_text_string(&credMap, &cred->credUsage, &tempLen, NULL);
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Period.");
                             }
 #endif  //__WITH_DTLS__ ||  __WITH_TLS__
 
                             if (0 == strcmp(OIC_JSON_PERIOD_NAME, name))
                             {
-                                cborFindResult = cbor_value_dup_text_string(&credMap, &cred->period, &len, NULL);
+                                cborFindResult = cbor_value_dup_text_string(&credMap, &cred->period, &tempLen, NULL);
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Period.");
                             }
 
@@ -1014,7 +1015,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size,
                             if (strcmp(OIC_JSON_EOWNERID_NAME, name)  == 0 && cbor_value_is_text_string(&credMap))
                             {
                                 char *eowner = NULL;
-                                cborFindResult = cbor_value_dup_text_string(&credMap, &eowner, &len, NULL);
+                                cborFindResult = cbor_value_dup_text_string(&credMap, &eowner, &tempLen, NULL);
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding eownerId Value.");
                                 if(NULL == cred->eownerID)
                                 {
@@ -1281,8 +1282,12 @@ static bool UpdatePersistentStorage(const OicSecCred_t *cred)
 
         if ((OC_STACK_OK == res) && payload)
         {
-            DATA_BLOB decryptedPayload = { .cbData = dwordSize, .pbData = payload };
-            DATA_BLOB encryptedPayload = { .cbData = 0, .pbData = NULL };
+            DATA_BLOB decryptedPayload;
+            DATA_BLOB encryptedPayload;
+            memset(&decryptedPayload, 0, sizeof(decryptedPayload));
+            memset(&encryptedPayload, 0, sizeof(encryptedPayload));
+            decryptedPayload.cbData = dwordSize;
+            decryptedPayload.pbData = payload;
 
             if (CryptProtectData(
                 &decryptedPayload,
@@ -1757,7 +1762,8 @@ static bool FillPrivateDataOfOwnerPSK(OicSecCred_t* receviedCred, const CAEndpoi
     }
     else
     {
-        VERIFY_SUCCESS(TAG, OIC_ENCODING_UNKNOW, ERROR);
+        OIC_LOG_V(ERROR, TAG, "Unknown credential encoding type: %u.", receviedCred->privateData.encoding);
+        goto exit;
     }
 
     OIC_LOG(INFO, TAG, "PrivateData of OwnerPSK was calculated successfully");
@@ -1835,8 +1841,8 @@ static bool FillPrivateDataOfSubOwnerPSK(OicSecCred_t* receivedCred, const CAEnd
     }
     else
     {
-        OIC_LOG(INFO, TAG, "Unknown credential encoding type.");
-        VERIFY_SUCCESS(TAG, OIC_ENCODING_UNKNOW, ERROR);
+        OIC_LOG_V(ERROR, TAG, "Unknown credential encoding type: %u.", receviedCred->privateData.encoding);
+        goto exit;
     }
 
     OIC_LOG(INFO, TAG, "PrivateData of SubOwnerPSK was calculated successfully");
@@ -1957,10 +1963,10 @@ static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehReques
                   * If some error is occured while ownership transfer,
                   * ownership transfer related resource should be revert back to initial status.
                   */
-                const OicSecDoxm_t* doxm =  GetDoxmResourceData();
-                if(doxm)
+                const OicSecDoxm_t* ownershipDoxm =  GetDoxmResourceData();
+                if(ownershipDoxm)
                 {
-                    if(!doxm->owned)
+                    if(!ownershipDoxm->owned)
                     {
                         OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
 
@@ -2041,7 +2047,6 @@ static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehReques
         {
             if(IsEmptyCred(cred))
             {
-                OicUuid_t emptyUuid = {.id={0}};
                 if(memcmp(cred->rownerID.id, emptyUuid.id, sizeof(emptyUuid.id)) != 0)
                 {
                     OIC_LOG(INFO, TAG, "CRED's rowner will be updated.");
@@ -2260,8 +2265,12 @@ OCStackResult InitCredResource()
 
         if (ret != OC_STACK_OK)
         {
-            DATA_BLOB encryptedPayload = { .cbData = dwordSize, .pbData = data };
-            DATA_BLOB decryptedPayload = { .cbData = 0, .pbData = NULL };
+            DATA_BLOB decryptedPayload;
+            DATA_BLOB encryptedPayload;
+            memset(&decryptedPayload, 0, sizeof(decryptedPayload));
+            memset(&encryptedPayload, 0, sizeof(encryptedPayload));
+            encryptedPayload.cbData = dwordSize;
+            encryptedPayload.pbData = data;
 
             if (CryptUnprotectData(
                 &encryptedPayload,
@@ -2595,7 +2604,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type,
                                         return ret;
                                     }
 
-                                    if(B64_OK != b64Decode((char*)wildCardCred->privateData.data, wildCardCred->privateData.len, pinBuffer, pinBufSize, &pinLength))
+                                    if(B64_OK != b64Decode((char*)wildCardCred->privateData.data, wildCardCred->privateData.len, (uint8_t*)pinBuffer, pinBufSize, &pinLength))
                                     {
                                         OIC_LOG (ERROR, TAG, "Failed to base64 decoding.");
                                         return ret;
@@ -2687,7 +2696,12 @@ OCStackResult AddTmpPskWithPIN(const OicUuid_t* tmpSubject, OicSecCredType_t cre
     }
 
     uint8_t privData[OWNER_PSK_LENGTH_128] = {0,};
-    OicSecKey_t privKey = {privData, OWNER_PSK_LENGTH_128, OIC_ENCODING_RAW};
+    OicSecKey_t privKey;
+    memset(&privKey, 0, sizeof(privKey));
+    privKey.data = privData;
+    privKey.len = OWNER_PSK_LENGTH_128;
+    privKey.encoding = OIC_ENCODING_RAW;
+
     OicSecCred_t* cred = NULL;
     int dtlsRes = DeriveCryptoKeyFromPassword((const unsigned char *)pin, pinSize, rownerID->id,
                                               UUID_LENGTH, PBKDF_ITERATIONS,
index dd67cb6..be82012 100644 (file)
@@ -319,7 +319,8 @@ OCStackResult CrlToCBORPayload(const OicSecCrl_t *crl, uint8_t **payload, size_t
     CborError cborEncoderResult = CborNoError;
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     cborEncoderResult = cbor_encoder_create_map(&encoder, &crlMap, mapSize);
@@ -787,18 +788,18 @@ void GetDerCrl(ByteArray_t* out)
 
     if (OIC_ENCODING_BASE64 == crl->encoding)
     {
-        size_t outSize = B64DECODE_OUT_SAFESIZE((crl->len + 1));
-        uint8_t *out = OICCalloc(1, outSize);
-        if (!out)
+        size_t decodeBufferSize = B64DECODE_OUT_SAFESIZE((crl->len + 1));
+        uint8_t *decodeBuffer = OICCalloc(1, decodeBufferSize);
+        if (!decodeBuffer)
         {
             OIC_LOG(ERROR, TAG, "Can't allocate memory for base64 str");
             return;
         }
         size_t len = 0;
 
-        if(B64_OK == b64Decode((char*)crl->data, crl->len, out, outSize, &len))
+        if(B64_OK == b64Decode((char*)crl->data, crl->len, decodeBuffer, decodeBufferSize, &len))
         {
-            memcpy(crl->data, out, len);
+            memcpy(crl->data, decodeBuffer, len);
             crl->len = (size_t)len;
 
             OIC_LOG (ERROR, TAG, "Crl successfully decoded to base64.");
@@ -807,7 +808,8 @@ void GetDerCrl(ByteArray_t* out)
         {
             OIC_LOG (ERROR, TAG, "Base64 decoding failed.");
         }
-        OICFree(out);
+
+        OICFree(decodeBuffer);
     }
 
     out->len = 0;
index 4c00338..3387d6a 100644 (file)
@@ -897,8 +897,7 @@ static OCStackApplicationResult DirectPairingDiscoveryHandler(void* ctx, OCDoHan
                 OCDevAddr endpoint;
                 memcpy(&endpoint, &clientResponse->devAddr, sizeof(OCDevAddr));
 
-                OCStackResult res = addDev(&g_dp_discover, &endpoint,
-                            clientResponse->connType, pconf);
+                res = addDev(&g_dp_discover, &endpoint, clientResponse->connType, pconf);
                 DeletePconfBinData(pconf);
                 if (OC_STACK_OK != res)
                 {
@@ -906,7 +905,6 @@ static OCStackApplicationResult DirectPairingDiscoveryHandler(void* ctx, OCDoHan
                     return OC_STACK_KEEP_TRANSACTION;
                 }
 
-
                 char rsrc_uri[MAX_URI_LENGTH+1] = {0};
                 int wr_len = snprintf(rsrc_uri, sizeof(rsrc_uri), "%s?%s=%s",
                           OC_RSRVD_WELL_KNOWN_URI, OC_RSRVD_RESOURCE_TYPE, OIC_RSRC_TYPE_SEC_DPAIRING);
@@ -932,9 +930,9 @@ static OCStackApplicationResult DirectPairingDiscoveryHandler(void* ctx, OCDoHan
                 cbData.cb = &DirectPairingPortDiscoveryHandler;
                 cbData.context = NULL;
                 cbData.cd = NULL;
-                OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
+                res = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
                         clientResponse->connType, OC_LOW_QOS, &cbData, NULL, 0);
-                if(OC_STACK_OK != ret)
+                if(OC_STACK_OK != res)
                 {
                     OIC_LOG(ERROR, TAG, "Failed to Secure Port Discovery");
                     return OC_STACK_KEEP_TRANSACTION;
index e0f339a..a5ee346 100644 (file)
@@ -167,7 +167,8 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm, uint8_t **payload, siz
     int64_t cborEncoderResult = CborNoError;
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     cborEncoderResult = cbor_encoder_create_map(&encoder, &doxmMap, CborIndefiniteLength);
@@ -271,11 +272,11 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm, uint8_t **payload, siz
         subOwner = NULL;
         LL_FOREACH(doxm->subOwners, subOwner)
         {
-            char* strUuid = NULL;
-            ret = ConvertUuidToStr(&subOwner->uuid, &strUuid);
+            char* strSubOwnerUuid = NULL;
+            ret = ConvertUuidToStr(&subOwner->uuid, &strSubOwnerUuid);
             VERIFY_SUCCESS(TAG, OC_STACK_OK == ret , ERROR);
-            cborEncoderResult = cbor_encode_text_string(&subOwners, strUuid, strlen(strUuid));
-            OICFree(strUuid);
+            cborEncoderResult = cbor_encode_text_string(&subOwners, strSubOwnerUuid, strlen(strSubOwnerUuid));
+            OICFree(strSubOwnerUuid);
             VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SubOwnerId Value");
         }
         cborEncoderResult = cbor_encoder_close_container(&doxmMap, &subOwners);
@@ -427,11 +428,11 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz
         VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Entering oxmType Array.")
 
         int i = 0;
-        size_t len = 0;
+        size_t oxmTypeStrlen = 0;
         while (cbor_value_is_valid(&oxmType) && cbor_value_is_text_string(&oxmType))
         {
             cborFindResult = cbor_value_dup_text_string(&oxmType, &doxm->oxmType[i++],
-                                                        &len, NULL);
+                                                        &oxmTypeStrlen, NULL);
             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding omxType text string.");
             cborFindResult = cbor_value_advance(&oxmType);
             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Advancing oxmType.");
@@ -602,16 +603,16 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz
         {
             OCStackResult convertRes = OC_STACK_ERROR;
             OicSecSubOwner_t* subOwner = NULL;
-            char* strUuid = NULL;
+            char* strSubOwnerUuid = NULL;
             size_t uuidLen = 0;
 
-            cborFindResult = cbor_value_dup_text_string(&subOwnerCbor, &strUuid, &uuidLen, NULL);
+            cborFindResult = cbor_value_dup_text_string(&subOwnerCbor, &strSubOwnerUuid, &uuidLen, NULL);
             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding SubOwnerId Value");
 
             subOwner = (OicSecSubOwner_t*)OICCalloc(1, sizeof(OicSecSubOwner_t));
             VERIFY_NOT_NULL(TAG, subOwner, ERROR);
 
-            convertRes = ConvertStrToUuid(strUuid, &subOwner->uuid);
+            convertRes = ConvertStrToUuid(strSubOwnerUuid, &subOwner->uuid);
             VERIFY_SUCCESS(TAG, OC_STACK_OK == convertRes, ERROR);
             subOwner->status = MOT_STATUS_DONE;
             LL_APPEND(doxm->subOwners, subOwner);
index 4b5ed5a..613941e 100644 (file)
@@ -133,7 +133,11 @@ OCStackResult SavePairingPSK(OCDevAddr *endpoint,
     }
 
     uint8_t pairingPSK[OWNER_PSK_LENGTH_128] = {0};
-    OicSecKey_t pairingKey = {pairingPSK, OWNER_PSK_LENGTH_128, OIC_ENCODING_RAW};
+    OicSecKey_t pairingKey;
+    memset(&pairingKey, 0, sizeof(pairingKey));
+    pairingKey.data = pairingPSK;
+    pairingKey.len = OWNER_PSK_LENGTH_128;
+    pairingKey.encoding = OIC_ENCODING_RAW;
 
     //Generating PairingPSK using OwnerPSK scheme
     CAResult_t pskRet = CAGenerateOwnerPSK((const CAEndpoint_t *)endpoint,
@@ -198,7 +202,8 @@ OCStackResult DpairingToCBORPayload(const OicSecDpairing_t *dpair, uint8_t **pay
     uint8_t mapSize = DPAIR_MAP_SIZE;
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     cborEncoderResult = cbor_encoder_create_map(&encoder, &dpairMap, mapSize);
@@ -445,16 +450,16 @@ static OCEntityHandlerResult HandleDpairingPostRequest (const OCEntityHandlerReq
 
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
             // Add temporary psk
-            OCStackResult res;
+            OCStackResult result;
             OicUuid_t subjectId = {.id={0}};
-            res = AddTmpPskWithPIN(&gDpair->pdeviceID,
+            result = AddTmpPskWithPIN(&gDpair->pdeviceID,
                            SYMMETRIC_PAIR_WISE_KEY,
                            (char*)pconf->pin.val, DP_PIN_LENGTH,
                            &gDpair->rownerID, &subjectId);
-            if(res != OC_STACK_OK ||
+            if(result != OC_STACK_OK ||
                     memcmp(&gDpair->pdeviceID, &subjectId, sizeof(OicUuid_t)))
             {
-                OIC_LOG_V(ERROR, TAG, "Failed to save the temporal PSK : %d", res);
+                OIC_LOG_V(ERROR, TAG, "Failed to save the temporal PSK : %d", result);
                 goto exit;
             }
 
@@ -525,7 +530,6 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ
         {
             res = CBORPayloadToDpair(payload, size, &newDpair);
         }
-
     }
     else
     {
@@ -541,8 +545,8 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ
         // Check if valid Put request
         VERIFY_SUCCESS(TAG, PRM_NOT_ALLOWED == newDpair->spm, ERROR);
 
-        const OicSecPconf_t *pconf = GetPconfResourceData();
-        VERIFY_NOT_NULL(TAG, pconf, ERROR);
+        const OicSecPconf_t *secPconf = GetPconfResourceData();
+        VERIFY_NOT_NULL(TAG, secPconf, ERROR);
 
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
         OCServerRequest * request = (OCServerRequest *)ehRequest->requestHandle;
@@ -551,14 +555,14 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ
         //Generate new credential
         OIC_LOG_V(INFO, TAG, "SavePairingPSK for %s(%d)", request->devAddr.addr,
                 request->devAddr.port);
-        OCStackResult res = SavePairingPSK(&request->devAddr, &newDpair->pdeviceID,
-                (OicUuid_t *)&pconf->rownerID, true);
-        VERIFY_SUCCESS(TAG, OC_STACK_OK == res, ERROR);
+        OCStackResult result = SavePairingPSK(&request->devAddr, &newDpair->pdeviceID,
+                (OicUuid_t *)&secPconf->rownerID, true);
+        VERIFY_SUCCESS(TAG, OC_STACK_OK == result, ERROR);
 #endif // __WITH_DTLS__ or __WITH_TLS__
 
         //Generate new acl
         OicSecPdAcl_t *pdAcl;
-        LL_FOREACH(pconf->pdacls, pdAcl)
+        LL_FOREACH(secPconf->pdacls, pdAcl)
         {
             OicSecAcl_t* acl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
             VERIFY_NOT_NULL(TAG, acl, ERROR);
index 543456d..9a5e066 100644 (file)
@@ -562,8 +562,7 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
             case CA_DTLS_PSK_KEY:
                 {
                     OicUuid_t uuid;
-                    memset(&uuid, 0x00, sizeof(uuid));
-                    OICStrcpy(uuid.id, sizeof(uuid.id), WILDCARD_SUBJECT_ID.id);
+                    memcpy(&uuid, &WILDCARD_SUBJECT_ID, sizeof(uuid));
 
                     //Load PreConfigured-PIN
                     const OicSecCred_t* cred = GetCredResourceData(&uuid);
@@ -592,7 +591,7 @@ int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
                                 return ret;
                             }
 
-                            if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufSize, &pinLength))
+                            if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, (uint8_t*)pinBuffer, pinBufSize, &pinLength))
                             {
                                 OIC_LOG (ERROR, TAG, "Failed to base64 decoding.");
                                 OICFree(pinBuffer);
@@ -663,8 +662,7 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
             case CA_DTLS_PSK_KEY:
                 {
                     OicUuid_t uuid;
-                    memset(&uuid, 0x00, sizeof(uuid));
-                    OICStrcpy(uuid.id, sizeof(uuid.id), WILDCARD_SUBJECT_ID.id);
+                    memcpy(&uuid, &WILDCARD_SUBJECT_ID, sizeof(uuid));
 
                     //Load PreConfigured-PIN
                     const OicSecCred_t* cred = GetCredResourceData(&uuid);
@@ -693,7 +691,7 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
                                 return ret;
                             }
 
-                            if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufSize, &pinLength))
+                            if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, (uint8_t*)pinBuffer, pinBufSize, &pinLength))
                             {
                                 OIC_LOG (ERROR, TAG, "Failed to base64 decoding.");
                                 OICFree(pinBuffer);
index 44758e2..68f11ba 100644 (file)
@@ -186,7 +186,7 @@ OCStackResult PconfToCBORPayload(const OicSecPconf_t *pconf,uint8_t **payload,si
     }
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
 
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
     cborEncoderResult = cbor_encoder_create_map(&encoder, &pconfMap, mapSize);
@@ -535,7 +535,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
 
                 while (cbor_value_is_valid(&pdAclArray))
                 {
-                    CborValue pdAclMap = { .parser = NULL};
+                    CborValue pdAclMap = { .parser = NULL };
                     OicSecPdAcl_t *pdacl = (OicSecPdAcl_t *) OICCalloc(1, sizeof(OicSecPdAcl_t));
                     VERIFY_NOT_NULL(TAG, pdacl, ERROR);
 
@@ -544,21 +544,21 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
 
                     while (cbor_value_is_valid(&pdAclMap))
                     {
-                        char* name = NULL;
-                        size_t len = 0;
-                        CborType type = cbor_value_get_type(&pdAclMap);
-                        if (type == CborTextStringType && cbor_value_is_text_string(&pdAclMap))
+                        char* pdAclMapName = NULL;
+                        size_t tempLen = 0;
+                        CborType pdAclMapType = cbor_value_get_type(&pdAclMap);
+                        if ((pdAclMapType == CborTextStringType) && cbor_value_is_text_string(&pdAclMap))
                         {
-                            cborFindResult = cbor_value_dup_text_string(&pdAclMap, &name,
-                                    &len, NULL);
+                            cborFindResult = cbor_value_dup_text_string(&pdAclMap, &pdAclMapName,
+                                    &tempLen, NULL);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get text");
                             cborFindResult = cbor_value_advance(&pdAclMap);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance value");
                         }
-                        if (name)
+                        if (pdAclMapName)
                         {
                             // Resources -- Mandatory
-                            if (strcmp(name, OIC_JSON_RESOURCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
+                            if (strcmp(pdAclMapName, OIC_JSON_RESOURCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
                             {
                                 int i = 0;
                                 CborValue resources = { .parser = NULL };
@@ -590,7 +590,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                         if (0 == strcmp(OIC_JSON_HREF_NAME, rMapName))
                                         {
                                             // TODO : Need to check data structure of OicSecPdAcl_t based on RAML spec.
-                                            cborFindResult = cbor_value_dup_text_string(&rMap, &pdacl->resources[i++], &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&rMap, &pdacl->resources[i++], &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Href Value.");
                                         }
 
@@ -609,7 +609,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                         {
                                             // TODO : Need to check data structure of OicSecPdAcl_t and assign based on RAML spec.
                                             char *rtData = NULL;
-                                            cborFindResult = cbor_value_dup_text_string(&rMap, &rtData, &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&rMap, &rtData, &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding RT Value.");
                                             OICFree(rtData);
                                         }
@@ -619,7 +619,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                         {
                                             // TODO : Need to check data structure of OicSecPdAcl_t and assign based on RAML spec.
                                             char *ifData = NULL;
-                                            cborFindResult = cbor_value_dup_text_string(&rMap, &ifData, &len, NULL);
+                                            cborFindResult = cbor_value_dup_text_string(&rMap, &ifData, &tempLen, NULL);
                                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding IF Value.");
                                             OICFree(ifData);
                                         }
@@ -641,7 +641,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                             }
 
                             // Permissions -- Mandatory
-                            if (strcmp(name, OIC_JSON_PERMISSION_NAME) == 0 && cbor_value_is_unsigned_integer(&pdAclMap))
+                            if (strcmp(pdAclMapName, OIC_JSON_PERMISSION_NAME) == 0 && cbor_value_is_unsigned_integer(&pdAclMap))
                             {
                                 uint64_t permission = 0;
                                 cborFindResult = cbor_value_get_uint64(&pdAclMap, &permission);
@@ -650,7 +650,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                             }
 
                             // Period -- Not mandatory
-                            if (strcmp(name, OIC_JSON_PERIODS_NAME) == 0 && cbor_value_is_array(&pdAclMap))
+                            if (strcmp(pdAclMapName, OIC_JSON_PERIODS_NAME) == 0 && cbor_value_is_array(&pdAclMap))
                             {
                                 int i = 0;
                                 CborValue period = { .parser = NULL };
@@ -665,7 +665,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                 while (cbor_value_is_text_string(&period) && cbor_value_is_text_string(&period))
                                 {
                                     cborFindResult = cbor_value_dup_text_string(&period,
-                                            &pdacl->periods[i++], &len, NULL);
+                                            &pdacl->periods[i++], &tempLen, NULL);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get text");
                                     cborFindResult = cbor_value_advance(&period);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance");
@@ -674,7 +674,7 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                             }
 
                             // Recurrence -- Not mandatory
-                            if (strcmp(name, OIC_JSON_RECURRENCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
+                            if (strcmp(pdAclMapName, OIC_JSON_RECURRENCES_NAME) == 0 && cbor_value_is_array(&pdAclMap))
                             {
                                 int i = 0;
                                 CborValue recurrences = { .parser = NULL };
@@ -688,13 +688,13 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                                 while (cbor_value_is_text_string(&recurrences) && cbor_value_is_text_string(&recurrences))
                                 {
                                     cborFindResult = cbor_value_dup_text_string(&recurrences,
-                                            &pdacl->recurrences[i++], &len, NULL);
+                                            &pdacl->recurrences[i++], &tempLen, NULL);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
                                     cborFindResult = cbor_value_advance(&recurrences);
                                     VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance");
                                 }
                             }
-                            if (type != CborMapType && cbor_value_is_valid(&pdAclMap))
+                            if (pdAclMapType != CborMapType && cbor_value_is_valid(&pdAclMap))
                             {
                                 cborFindResult = cbor_value_advance(&pdAclMap);
                                 VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance");
@@ -705,8 +705,8 @@ OCStackResult CBORPayloadToPconf(const uint8_t *cborPayload, size_t size, OicSec
                             cborFindResult = cbor_value_advance(&pdAclArray);
                             VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to advance");
                         }
-                        OICFree(name);
-                        name = NULL;
+                        OICFree(pdAclMapName);
+                        pdAclMapName = NULL;
                     }
                     pdacl->next = NULL;
                     if (headPdacl == NULL)
@@ -1081,9 +1081,9 @@ OCStackResult InitPconfResource()
     {
         gPconf = GetPconfDefault();
 
-        // device id from doxm
+        // Device id from doxm
         OicUuid_t deviceId = {.id = {0}};
-        OCStackResult ret = GetDoxmDeviceID( &deviceId);
+        ret = GetDoxmDeviceID(&deviceId);
         VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
         memcpy(&gPconf->deviceID, &deviceId, sizeof(OicUuid_t));
     }
index ae7f8f0..d929dce 100644 (file)
@@ -112,7 +112,8 @@ OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat, uint8_t **payload,
     int64_t cborEncoderResult = CborNoError;
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     if (false == writableOnly)
index e60e2ec..cebbe37 100644 (file)
@@ -428,6 +428,11 @@ bool SRMIsSecurityResourceURI(const char* uri)
         return false;
     }
 
+#ifdef _MSC_VER
+    // The strings below are const but they are also marked as extern so they cause warnings.
+#pragma warning(push)
+#pragma warning(disable:4204)
+#endif
     const char *rsrcs[] = {
         OIC_RSRC_SVC_URI,
         OIC_RSRC_AMACL_URI,
@@ -442,6 +447,10 @@ bool SRMIsSecurityResourceURI(const char* uri)
         OC_RSRVD_PROV_CRL_URL
     };
 
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
     // Remove query from Uri for resource string comparison
     size_t uriLen = strlen(uri);
     char *query = strchr (uri, '?');
index eb9a3a4..bf09671 100644 (file)
@@ -126,7 +126,7 @@ const char * OIC_JSON_CREDUSAGE_NAME = "credusage";
 const char * OIC_JSON_REVOCATION_STATUS_NAME = "revstat";
 const char * OIC_JSON_SERVICE_DEVICE_ID = "svcdid";
 const char * OIC_JSON_SERVICE_TYPE = "svct";
-const char* OIC_JSON_VALIDITY_NAME = "validity";
+const char * OIC_JSON_VALIDITY_NAME = "validity";
 const char * OIC_JSON_PERIOD_NAME = "period";
 const char * OIC_JSON_PERIODS_NAME = "prds";
 const char * OIC_JSON_CRMS_NAME = "crms";
index 5cba4a6..4864199 100644 (file)
@@ -31,7 +31,6 @@ bool is_leap_year(int yy)
 {
     int yyyy = yy + TM_BASE_YEAR;
 
-    bool bLeap = false;
     if (yyyy % 100 == 0)
     {
         return yyyy % 400 == 0;
index 77398c5..781ff97 100644 (file)
@@ -99,7 +99,7 @@ OCStackResult SVCToCBORPayload(const OicSecSvc_t *svc, uint8_t **cborPayload,
     CborEncoder svcArray;
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
 
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
@@ -348,11 +348,11 @@ static OCEntityHandlerResult HandleSVCPostRequest(const OCEntityHandlerRequest *
             LL_APPEND(gSvc, newSvc);
 
             // Convert SVC data into JSON for update to persistent storage
-            size_t size = 0;
+            size_t cborSize = 0;
             uint8_t *cborPayload = NULL;
-            res = SVCToCBORPayload(gSvc, &cborPayload, &size);
+            res = SVCToCBORPayload(gSvc, &cborPayload, &cborSize);
             if (cborPayload && OC_STACK_OK == res &&
-                UpdateSecureResourceInPS(OIC_JSON_SVC_NAME, cborPayload, size) == OC_STACK_OK)
+                UpdateSecureResourceInPS(OIC_JSON_SVC_NAME, cborPayload, cborSize) == OC_STACK_OK)
             {
                 ehRet = OC_EH_CHANGED;
             }
index 4159bcc..3350da5 100644 (file)
@@ -99,7 +99,8 @@ OCStackResult VerToCBORPayload(const OicSecVer_t *ver, uint8_t **payload, size_t
     char* strUuid = NULL;
 
     uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
-    VERIFY_NOT_NULL(TAG, outPayload, ERROR);
+    VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
+
     cbor_encoder_init(&encoder, outPayload, cborLen, 0);
 
     cborEncoderResult |= cbor_encoder_create_map(&encoder, &verMap, mapSize);
index 83ef28c..45aed57 100644 (file)
@@ -459,7 +459,8 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr)
             jsonObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_PERMISSION_NAME);
             VERIFY_NOT_NULL(TAG, jsonObj, ERROR);
             VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
-            ace->permission = jsonObj->valueint;
+            VERIFY_SUCCESS(TAG, jsonObj->valueint <= UINT16_MAX, ERROR);
+            ace->permission = (uint16_t)jsonObj->valueint;
 
             //Validity -- Not Mandatory
             cJSON *jsonValidityObj = cJSON_GetObjectItem(jsonAcl, OIC_JSON_VALIDITY_NAME);
@@ -510,20 +511,20 @@ OicSecAcl_t* JSONToAclBin(const char * jsonStr)
                         VERIFY_NOT_NULL(TAG, validity->recurrences, ERROR);
 
                         cJSON *jsonRecur = NULL;
-                        for(size_t i = 0; i < validity->recurrenceLen; i++)
+                        for(size_t j = 0; j < validity->recurrenceLen; j++)
                         {
 // Needs to be removed once IOT-1746 is resolved.
 #ifdef _MSC_VER
 #pragma warning(suppress : 4267)
-                            jsonRecur = cJSON_GetArrayItem(jsonRecurObj, i);
+                            jsonRecur = cJSON_GetArrayItem(jsonRecurObj, j);
 
 #else
-                            jsonRecur = cJSON_GetArrayItem(jsonRecurObj, i);
+                            jsonRecur = cJSON_GetArrayItem(jsonRecurObj, j);
 
 #endif
                             VERIFY_NOT_NULL(TAG, jsonRecur, ERROR);
-                            validity->recurrences[i] = OICStrdup(jsonRecur->valuestring);
-                            VERIFY_NOT_NULL(TAG, validity->recurrences[i], ERROR);
+                            validity->recurrences[j] = OICStrdup(jsonRecur->valuestring);
+                            VERIFY_NOT_NULL(TAG, validity->recurrences[j], ERROR);
                         }
                     }
                 }
@@ -883,7 +884,8 @@ OicSecCred_t * JSONToCredBin(const char * jsonStr)
             if(jsonObj)
             {
                 VERIFY_SUCCESS(TAG, cJSON_Number == jsonObj->type, ERROR);
-                cred->credId = jsonObj->valueint;
+                VERIFY_SUCCESS(TAG, jsonObj->valueint <= UINT16_MAX, ERROR);
+                cred->credId = (uint16_t)jsonObj->valueint;
             }
 
             //subject -- Mandatory