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

Handle bracketed IPv6 addresses without ports #6057

Merged
merged 2 commits into from Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pdns/dnsdistdist/Makefile.am
Expand Up @@ -178,6 +178,7 @@ testrunner_SOURCES = \
test-dnsdist_cc.cc \
test-dnsdistpacketcache_cc.cc \
test-dnscrypt_cc.cc \
test-iputils_hh.cc \
dnsdist.hh \
dnsdist-cache.cc dnsdist-cache.hh \
dnsdist-ecs.cc dnsdist-ecs.hh \
Expand Down
1 change: 1 addition & 0 deletions pdns/dnsdistdist/test-iputils_hh.cc
20 changes: 13 additions & 7 deletions pdns/misc.cc
Expand Up @@ -716,15 +716,21 @@ int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret)
unsigned int port;
if(addr[0]=='[') { // [::]:53 style address
string::size_type pos = addr.find(']');
if(pos == string::npos || pos + 2 > addr.size() || addr[pos+1]!=':')
if(pos == string::npos)
return -1;
ourAddr.assign(addr.c_str() + 1, pos-1);
try {
port = pdns_stou(addr.substr(pos+2));
portSet = true;
}
catch(std::out_of_range) {
return -1;
if (pos + 1 == addr.size()) {
port = 0;
Copy link
Member

Choose a reason for hiding this comment

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

It looks like setting port to 0 without setting portSet to true is useless?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmmm yes. Will change that if()...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rgacogne fixed this!

} else {
if (pos + 2 > addr.size() || addr[pos+1]!=':')
return -1;
try {
port = pdns_stou(addr.substr(pos+2));
portSet = true;
}
catch(std::out_of_range) {
return -1;
}
}
}
ret->sin6_scope_id=0;
Expand Down
9 changes: 9 additions & 0 deletions pdns/test-iputils_hh.cc
Expand Up @@ -34,6 +34,15 @@ BOOST_AUTO_TEST_CASE(test_ComboAddress) {
withport = ComboAddress("[::]:5300", 53);
BOOST_CHECK_EQUAL(withport.sin4.sin_port, htons(5300));

ComboAddress defaultport("213.244.168.210");
BOOST_CHECK_EQUAL(defaultport.sin4.sin_port, htons(0));

defaultport = ComboAddress("[::1]");
BOOST_CHECK_EQUAL(defaultport.sin4.sin_port, htons(0));

defaultport = ComboAddress("::1");
BOOST_CHECK_EQUAL(defaultport.sin4.sin_port, htons(0));

// Verify that 2 'empty' ComboAddresses are equal, used in syncres.hh to
// signal auth-zones
ComboAddress a = ComboAddress();
Expand Down