else
{
unsigned char * lastCert = (unsigned char *)OICMalloc((len + 1) * sizeof(unsigned char));
+ if (lastCert == NULL)
+ {
+ goto exit;
+ }
memcpy(lastCert, buf + pos, len);
lastCert[len] = 0x00;
ret = mbedtls_x509_crt_parse(crt, lastCert, len + 1);
newCredential.eownerID = OICCalloc(1, sizeof(OicUuid_t));
if(NULL == newCredential.eownerID)
{
+ OICFree(secPayload);
return OC_STACK_NO_MEMORY;
}
}
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to convert UUID to str");
+ OICFree(strUuid);
SetMOTResult(motCtx, res);
return res;
}
OIC_LOG(ERROR, TAG, "Internal error in PDMDeleteDevice");
OICFree(strUuid);
SetMOTResult(motCtx, res);
+ return res;
}
}
else if(PDM_DEVICE_INIT == deviceState)
OICFree( cred->privateData.data );
cred->privateData.data = (uint8_t *)OICCalloc(1, outSize + 1);
- VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR);
+ if (cred->privateData.data == NULL)
+ {
+ OICFree(b64Buf);
+ res = OC_STACK_ERROR;
+ goto exit;
+ }
strncpy((char*)(cred->privateData.data), b64Buf, outSize);
cred->privateData.data[outSize] = '\0';
if(!ownerCredential)
{
OIC_LOG(ERROR, TAG, "Can not find OwnerPSK.");
+ OICFree(secPayload);
return OC_STACK_NO_RESOURCE;
}
{
case CT_ADAPTER_TCP:
prefix = (isSecure == true) ? COAPS_TCP_PREFIX : COAP_TCP_PREFIX;
+ /*FALLTHROUGH*/
case CT_ADAPTER_IP:
switch(connType & CT_MASK_FLAGS & ~CT_FLAG_SECURE)
{
sqlite3_finalize(stmt);
OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
- return OC_STACK_OK;
+ return ret;
}
OCStackResult OTMSetState(const OicUuid_t *uuid, int state)
res = sqlite3_bind_text(stmt, 1, uuidStr, strlen(uuidStr), SQLITE_TRANSIENT);
PDM_VERIFY_SQLITE_OK(TAG, res, NULL, ERROR, OC_STACK_ERROR);
- while (SQLITE_ROW == sqlite3_step(stmt))
+ if (SQLITE_ROW == sqlite3_step(stmt))
{
*state = sqlite3_column_int(stmt, 1);
OIC_LOG_V(DEBUG, TAG, "%s state is %d", uuidStr, *state);
ret = OC_STACK_OK;
- break;
}
OICFree(uuidStr);
res = sqlite3_prepare_v2(g_db, sqlStat, (int)sizeof(sqlStat), &stmt, 0);
PDM_VERIFY_SQLITE_OK(TAG, res, stmt, ERROR, OC_STACK_ERROR);
- while (SQLITE_ROW == sqlite3_step(stmt))
+ if (SQLITE_ROW == sqlite3_step(stmt))
{
int tempId = sqlite3_column_int(stmt, PDM_FIRST_INDEX);
OIC_LOG_V(DEBUG, TAG, "ID is %d", tempId);
res = sqlite3_bind_int(stmt, PDM_BIND_INDEX_FIRST, id);
PDM_VERIFY_SQLITE_OK(TAG, res, stmt, ERROR, OC_STACK_ERROR);
- while (SQLITE_ROW == sqlite3_step(stmt))
+ if (SQLITE_ROW == sqlite3_step(stmt))
{
const void *ptr = sqlite3_column_blob(stmt, PDM_FIRST_INDEX);
memcpy(uid, ptr, sizeof(OicUuid_t));
}
cred->credUsage= (char *)OICCalloc(1, strlen(TRUST_CA)+1 );
- VERIFY_NON_NULL_RET(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY);
+ if (cred->credUsage == NULL)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s cant alloc credUsage", __func__);
+ OICFree(cred);
+ return OC_STACK_NO_MEMORY;
+ }
OICStrcpy(cred->credUsage, strlen(TRUST_CA) + 1, TRUST_CA);
cred->credType = SIGNED_ASYMMETRIC_KEY;
cred->credUsage= (char *)OICCalloc(1, strlen(PRIMARY_CERT)+1 );
VERIFY_NON_NULL_RET(TAG, cred->credUsage, ERROR, OC_STACK_NO_MEMORY);
+ if (cred->credUsage == NULL)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s cant alloc credUsage", __func__);
+ OICFree(cred);
+ return OC_STACK_NO_MEMORY;
+ }
OICStrcpy(cred->credUsage, strlen(PRIMARY_CERT) + 1, PRIMARY_CERT) ;
cred->credType = SIGNED_ASYMMETRIC_KEY;
OicSecKey_t *privateData = &cred->privateData;
privateData->data = (uint8_t *)OICCalloc(1, key->len);
VERIFY_NON_NULL_RET(TAG, privateData->data, ERROR, OC_STACK_NO_MEMORY);
+ if (privateData->data == NULL)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s cant alloc publicData->data", __func__);
+ OICFree(publicData->data);
+ return OC_STACK_NO_MEMORY;
+ }
memcpy(privateData->data, key->data, key->len);
privateData->len = key->len;
privateData->encoding = key->encoding;
if (OC_STACK_OK != result)
{
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : encoding error %d\n", result);
+ OICFree(subID);
return OC_STACK_ERROR;
}
destDev->endpoint.addr);
if (OC_STACK_OK != result)
{
+ OICFree(subID);
OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : encoding error %d\n", result);
return OC_STACK_ERROR;
}
cbor_parser_init(cborPayload, size, 0, &parser, &amaclCbor);
OicSecAmacl_t *headAmacl = (OicSecAmacl_t *)OICCalloc(1, sizeof(OicSecAmacl_t));
+ VERIFY_NON_NULL(TAG, headAmacl, ERROR);
CborValue amaclMap = { .parser = NULL };
cborFindResult = cbor_value_enter_container(&amaclCbor, &amaclMap);
if(B64_OK != b64Decode((char*)wildCardCred->privateData.data, wildCardCred->privateData.len, pinBuffer, pinBufSize, &pinLength))
{
OIC_LOG (ERROR, TAG, "Failed to base64 decoding.");
+ OICFree(pinBuffer);
return ret;
}
}
if (OC_STACK_OK == GetSecureVirtualDatabaseFromPS(OIC_CBOR_CRL_NAME, &data, &size) && data &&
OC_STACK_OK == CBORPayloadToCrl(data, size, &crl))
{
- return crl->CrlData.data;
+ uint8_t *res = OICMalloc(crl->CrlData.len);
+ memcpy(res, crl->CrlData.data, crl->CrlData.len);
+ DeleteCrl(crl);
+ return res;
}
return NULL;
}
if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufSize, &pinLength))
{
OIC_LOG (ERROR, TAG, "Failed to base64 decoding.");
+ OICFree(pinBuffer);
return ret;
}
}
if(B64_OK != b64Decode((char*)cred->privateData.data, cred->privateData.len, pinBuffer, pinBufSize, &pinLength))
{
OIC_LOG (ERROR, TAG, "Failed to base64 decoding.");
+ OICFree(pinBuffer);
return ret;
}
}
uint8_t *pin = NULL;
cborFindResult = cbor_value_dup_byte_string(&pconfMap, &pin, &len, NULL);
VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed to get value");
- memcpy(pconf->pin.val, pin, len);
+ memcpy(pconf->pin.val, pin, len > 8 ? 8 : len);
OICFree(pin);
}
fp = ps->open(SVR_DB_DAT_FILE_NAME, "rb");
if (NULL == fp)
{
+ OICFree(plaintext);
OIC_LOG(ERROR, TAG, "ps->open() Failed");
return OC_STACK_ERROR;
}