Skip to content

Commit dbe78c9

Browse files
Proper checks in pp1_create_hdr for IPv4, IPv6
1 parent d074bc9 commit dbe78c9

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/proxy_protocol.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,15 +753,33 @@ static uint8_t *pp1_create_hdr(const pp_info_t *pp_info, uint16_t *pp1_hdr_len,
753753
else if (pp_info->address_family == ADDR_FAMILY_INET || pp_info->address_family == ADDR_FAMILY_INET6)
754754
{
755755
const char *fam = pp_info->address_family == ADDR_FAMILY_INET ? "TCP4" : "TCP6";
756-
if (strlen(pp_info->src_addr) > 39)
756+
if (pp_info->address_family == ADDR_FAMILY_INET)
757757
{
758-
*error = -ERR_PP1_IPV4_SRC_IP;
759-
return NULL;
758+
struct in_addr in;
759+
if (inet_pton(AF_INET, pp_info->src_addr, &in) != 1)
760+
{
761+
*error = -ERR_PP1_IPV4_SRC_IP;
762+
return NULL;
763+
}
764+
if (inet_pton(AF_INET, pp_info->dst_addr, &in) != 1)
765+
{
766+
*error = -ERR_PP1_IPV4_DST_IP;
767+
return NULL;
768+
}
760769
}
761-
if (strlen(pp_info->dst_addr) > 39)
770+
else if (pp_info->address_family == ADDR_FAMILY_INET6)
762771
{
763-
*error = -ERR_PP1_IPV4_DST_IP;
764-
return NULL;
772+
struct in6_addr in6;
773+
if (inet_pton(AF_INET6, pp_info->src_addr, &in6) != 1)
774+
{
775+
*error = -ERR_PP1_IPV6_SRC_IP;
776+
return NULL;
777+
}
778+
if (inet_pton(AF_INET6, pp_info->dst_addr, &in6) != 1)
779+
{
780+
*error = -ERR_PP1_IPV6_DST_IP;
781+
return NULL;
782+
}
765783
}
766784
char src_addr[39+1];
767785
char dst_addr[39+1];

0 commit comments

Comments
 (0)