}
coap_opt_t *option = NULL;
- char optionResult[CA_MAX_URI_LENGTH] = {0};
+ char *optionResult = (char *)OICCalloc(1, CA_MAX_URI_LENGTH * sizeof(char));
+ if (NULL == optionResult)
+ {
+ goto exit;
+ }
uint32_t idx = 0;
uint32_t optionLength = 0;
bool isfirstsetflag = false;
while ((option = coap_option_next(&opt_iter)))
{
- char buf[COAP_MAX_PDU_SIZE] = {0};
+ char *buf = (char *)OICCalloc(1, COAP_MAX_PDU_SIZE * sizeof(char));
+ if (NULL == buf)
+ {
+ goto exit;
+ }
+
uint32_t bufLength =
CAGetOptionData(opt_iter.type, (uint8_t *)(COAP_OPT_VALUE(option)),
- COAP_OPT_LENGTH(option), (uint8_t *)buf, sizeof(buf));
+ COAP_OPT_LENGTH(option), (uint8_t *)buf, COAP_MAX_PDU_SIZE);
if (bufLength)
{
OIC_LOG_V(DEBUG, TAG, "COAP URI element : %s", buf);
optionResult[optionLength] = '/';
optionLength++;
// Make sure there is enough room in the optionResult buffer
- if ((optionLength + bufLength) < sizeof(optionResult))
+ if ((optionLength + bufLength) < CA_MAX_URI_LENGTH)
{
memcpy(&optionResult[optionLength], buf, bufLength);
optionLength += bufLength;
}
else
{
+ OICFree(buf);
goto exit;
}
}
if (COAP_OPTION_URI_PATH == opt_iter.type)
{
// Make sure there is enough room in the optionResult buffer
- if (optionLength < sizeof(optionResult))
+ if (optionLength < CA_MAX_URI_LENGTH)
{
optionResult[optionLength] = '/';
optionLength++;
}
else
{
+ OICFree(buf);
goto exit;
}
}
if (false == isQueryBeingProcessed)
{
// Make sure there is enough room in the optionResult buffer
- if (optionLength < sizeof(optionResult))
+ if (optionLength < CA_MAX_URI_LENGTH)
{
optionResult[optionLength] = '?';
optionLength++;
}
else
{
+ OICFree(buf);
goto exit;
}
}
else
{
// Make sure there is enough room in the optionResult buffer
- if (optionLength < sizeof(optionResult))
+ if (optionLength < CA_MAX_URI_LENGTH)
{
optionResult[optionLength] = ';';
optionLength++;
}
else
{
+ OICFree(buf);
goto exit;
}
}
}
// Make sure there is enough room in the optionResult buffer
- if ((optionLength + bufLength) < sizeof(optionResult))
+ if ((optionLength + bufLength) < CA_MAX_URI_LENGTH)
{
memcpy(&optionResult[optionLength], buf, bufLength);
optionLength += bufLength;
}
else
{
+ OICFree(buf);
goto exit;
}
}
}
}
}
+ OICFree(buf);
}
unsigned char* token = NULL;
{
OIC_LOG(ERROR, TAG, "Out of memory");
OICFree(outInfo->options);
+ OICFree(optionResult);
return CA_MEMORY_ALLOC_FAILED;
}
memcpy(outInfo->token, token, token_length);
OIC_LOG(ERROR, TAG, "Out of memory");
OICFree(outInfo->options);
OICFree(outInfo->token);
+ OICFree(optionResult);
return CA_MEMORY_ALLOC_FAILED;
}
memcpy(outInfo->payload, pdu->data, dataSize);
outInfo->payloadSize = dataSize;
}
- if (optionResult[0] != '\0')
+ if (optionResult[0] != '\0' && optionLength>=0 && optionLength<CA_MAX_URI_LENGTH )
{
+ optionResult[optionLength] = '\0';
OIC_LOG_V(DEBUG, TAG, "URL length:%zu", strlen(optionResult));
outInfo->resourceUri = OICStrdup(optionResult);
if (!outInfo->resourceUri)
OIC_LOG(ERROR, TAG, "Out of memory");
OICFree(outInfo->options);
OICFree(outInfo->token);
+ OICFree(optionResult);
return CA_MEMORY_ALLOC_FAILED;
}
}
OIC_LOG(ERROR, TAG, "Out of memory");
OICFree(outInfo->options);
OICFree(outInfo->token);
+ OICFree(optionResult);
return CA_MEMORY_ALLOC_FAILED;
}
}
#endif
+ OICFree(optionResult);
return CA_STATUS_OK;
exit:
OIC_LOG(ERROR, TAG, "buffer too small");
OICFree(outInfo->options);
+ OICFree(optionResult);
return CA_STATUS_FAILED;
}