Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipv6 host validation support #3250

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/aws-cpp-sdk-core/source/utils/DNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <aws/core/utils/DNS.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/common/host_utils.h>

namespace Aws
{
Expand Down Expand Up @@ -49,7 +50,7 @@ namespace Aws
return false;
}

return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); });
return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }) || aws_host_utils_is_ipv6(aws_byte_cursor_from_c_str(host.c_str()), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

two questions:

  • why are we using the C function aws_byte_cursor_from_c_str instead of the cpp binding ByteBufFromCString. when using the CRT we should prefer C++ binding in the CRT as opposed to direct C calls.

  • Why not create a CRT C++ binding for aws_host_utils_is_ipv6 instead of just calling the C function? We should create small and reusable bindings when we can. Calling the CRT C directly is something that we want to try to avoid.

}
}
}
26 changes: 26 additions & 0 deletions tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,29 @@ TEST_F(DnsTest, TestHost)
ASSERT_FALSE(IsValidHost("0123456789012345678901234567890123456789012345678901234567890123.com")); // 64 characters

}

TEST_F(DnsTest, TestIPV6)
{
Aws::Vector< std::pair<Aws::String, bool> > inputs = {
{"2001:0db8:85a3:0000:0000:8a2e:0370:7334", true},
{"2001:DB8:85A3::8A2E:370:7334", true},
{"::ffff", true},
{"::", true},
{"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",true},
{"2001:db8:85a3:0:0:8a2e:370:7334",true},
{"2001:db8:85a3:0000:0000:8a2e:0370:7334:1", false},
{"2001:db8:85a3:0000", false},
{"2001:0db8:85a3:0000:0000:8a2e:0370:7334:", false},
{"g001:0db8:85a3:0000:0000:8a2e:0370:7334", false},
{"2001:db8::85a3::1", false},
{":2001:db8:85a3:0000:0000:8a2e:0370:7334", false},
{"0:0:0:0:0:0:0:0", true},
{"2001:db8::", true}
};

for(auto t : inputs)
{
ASSERT_EQ(IsValidHost(t.first), t.second);
}

}
Loading