Commit 942120c6 authored by Alex Kelley's avatar Alex Kelley Committed by Kevin Kane

IOT-1835 Make resource/csdk/security W4 compliant.

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: default avatarAlex Kelley <alexke@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17399Reviewed-by: default avatarKevin Kane <kkane@microsoft.com>
Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
parent ef6f47b8
......@@ -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':
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;