Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/source/Ice/Network.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,32 @@ STATUS socketWrite(INT32 sockfd, const void* pBuffer, SIZE_T length)

BOOL isIpAddr(PCHAR hostname, UINT16 length)
{
BOOL status = TRUE;
int offset = 0;
UINT32 ip_1, ip_2, ip_3, ip_4, ip_5, ip_6, ip_7, ip_8;
if (hostname == NULL || length > MAX_ICE_CONFIG_URI_LEN) {
DLOGW("Provided NULL hostname");
status = FALSE;
} else {
status = (SSCANF(hostname, IPV4_TEMPLATE, &ip_1, &ip_2, &ip_3, &ip_4) == 4 && ip_1 >= 0 && ip_1 <= 255 && ip_2 >= 0 && ip_2 <= 255 &&
ip_3 >= 0 && ip_3 <= 255 && ip_4 >= 0 && ip_4 <= 255) ||
(SSCANF(hostname, IPV6_TEMPLATE, &ip_1, &ip_2, &ip_3, &ip_4, &ip_5, &ip_6, &ip_7, &ip_8) == 8);

if (hostname == NULL) {
DLOGW("Provided NULL hostname.");
return FALSE;
}
if (length > MAX_ICE_CONFIG_URI_LEN) {
DLOGW("Provided invalid hostname length: %u.", length);
return FALSE;
}
return status;

// Check if IPv4 address.
if (sscanf(hostname, "%u.%u.%u.%u%n", &ip_1, &ip_2, &ip_3, &ip_4, &offset) == 4 && ip_1 <= 255 && ip_2 <= 255 && ip_3 <= 255 && ip_4 <= 255 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the IPV4/IPV6 template still used?
Also suggest to use the macro version SSCANF and STRLEN

offset == strlen(hostname)) {
return TRUE;
}

// Check if IPv6 address.
offset = 0;
if (sscanf(hostname, "%x:%x:%x:%x:%x:%x:%x:%x%n", &ip_1, &ip_2, &ip_3, &ip_4, &ip_5, &ip_6, &ip_7, &ip_8, &offset) == 8 &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do checks here as similar to the <= 255 done for IPv4?

offset == strlen(hostname)) {
return TRUE;
}

return FALSE;
}

STATUS getIpAddrFromDnsHostname(PCHAR hostname, PCHAR address, UINT16 lengthSrc, UINT16 maxLenDst)
Expand Down
Loading