out->port = in->port;
out->ifindex = in->ifindex;
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
- memcpy(out->routeData, in->routeData, sizeof(out->routeData));
+ /* This assert is to prevent accidental mismatch between address size macros defined in
+ * RI and CA and cause crash here. */
+ OC_STATIC_ASSERT(MAX_ADDR_STR_SIZE_CA == MAX_ADDR_STR_SIZE,
+ "Address size mismatch between RI and CA");
+ memcpy(out->routeData, in->routeData, sizeof(in->routeData));
#endif
}
out->flags = OCToCATransportFlags(in->flags);
OICStrcpy(out->addr, sizeof(out->addr), in->addr);
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
- memcpy(out->routeData, in->routeData, sizeof(out->routeData));
+ /* This assert is to prevent accidental mismatch between address size macros defined in
+ * RI and CA and cause crash here. */
+ OC_STATIC_ASSERT(MAX_ADDR_STR_SIZE_CA == MAX_ADDR_STR_SIZE,
+ "Address size mismatch between RI and CA");
+ memcpy(out->routeData, in->routeData, sizeof(in->routeData));
#endif
out->port = in->port;
out->ifindex = in->ifindex;
}
/**
- * Encode an address string to match RFC6874.
+ * Encode an address string to match RFC 6874.
*
* @param outputAddress a char array to be written with the encoded string.
*
VERIFY_NON_NULL(inputAddress, FATAL, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL(outputAddress, FATAL, OC_STACK_INVALID_PARAM);
- /** @todo Use a max IPv6 string length instead of CA_MAX_URI_LENGTH. */
-#define ENCODE_MAX_INPUT_LENGTH CA_MAX_URI_LENGTH
-
- size_t inputLength = strnlen(inputAddress, ENCODE_MAX_INPUT_LENGTH);
-
- if (inputLength >= ENCODE_MAX_INPUT_LENGTH)
- {
- OIC_LOG(ERROR, TAG,
- "encodeAddressForRFC6874 failed: Invalid input string: too long/unterminated!");
- return OC_STACK_INVALID_PARAM;
- }
+ size_t inputLength = strnlen(inputAddress, outputSize);
// inputSize includes the null terminator
size_t inputSize = inputLength + 1;
// Fail if we don't have room for encoded string's two additional chars
if (outputSize < (inputSize + 2))
{
- OIC_LOG(ERROR, TAG, "encodeAddressForRFC6874 failed: Input string is already encoded");
+ OIC_LOG(ERROR, TAG, "encodeAddressForRFC6874 failed: encoded output will not fit!");
return OC_STACK_ERROR;
}
- // Restore the null terminator with an escaped '%' character, per RFC6874
+ // Restore the null terminator with an escaped '%' character, per RFC 6874
OICStrcpy(outputAddress, scopeIdPart - addressPart, addressPart);
strcat(outputAddress, "%25");
strcat(outputAddress, scopeIdPart);