Ticket #4690 (closed Bugs: fixed)
boost::asio::ip::tcp::resolver fails to resolve query if service_name is empty
Description
Documentation:
service_name
A string identifying the requested service. This may be a descriptive name or a numeric string corresponding to a port number. May be an empty string, in which case all resolved endpoints will have a port number of 0.
If empty service_name is specified, resolver returns error. According to documentation, it should resolve to endpoint which will have port number of 0.
Test program attached.
My system: 2.6-RELEASE DragonFly? v2.6.3.43.gb67e7-RELEASE Boost 1.44 from pkgsrc. I think all systems are affected.
Attachments
Change History
comment:1 Changed 5 years ago by chris_kohlhoff
- Status changed from new to closed
- Resolution set to worksforme
I assume this is some sort of linux system? I cannot reproduce any such error on mine.
Using the following slightly modified version of your testcase:
#include <iostream> #include <boost/asio.hpp> void print_result(const char* serv, boost::asio::ip::tcp::resolver::iterator iter, const boost::system::error_code& ec) { if( ec ) std::cerr << "service: '" << serv << "' FAIL: " << ec.message() << "\n"; else { std::cerr << "service: '" << serv << "' OK\n"; std::cerr << "endpoint: " << iter->endpoint() << "\n"; } } void do_resolv(const char* serv) { boost::asio::io_service io; boost::asio::ip::tcp::resolver resolver(io); boost::asio::ip::tcp::resolver::query q("127.0.0.1", serv); boost::system::error_code ec; boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(q,ec); print_result(serv, iter, ec); } int main() { do_resolv(""); do_resolv("12345"); do_resolv("ftp"); return 0; }
I get the following output:
service: '' OK endpoint: 127.0.0.1:0 service: '12345' OK endpoint: 127.0.0.1:12345 service: 'ftp' OK endpoint: 127.0.0.1:21
The problem may be specific to your target platform, in which case you will probably need to do some debugging to find out what is going on. Please reopen the bug if you find more information.
comment:2 Changed 5 years ago by Gennady Proskurin <gprspb@…>
- Status changed from closed to reopened
- Resolution worksforme deleted.
Changed 5 years ago by Gennady Proskurin <gprspb@…>
- attachment resolv.gdb
added
gdb debug session
comment:3 Changed 5 years ago by Gennady Proskurin <gprspb@…>
As you see from debug, empty servname is propagated down to getaddrinfo, which causes error. I think boost should replace empty string with something like "0" somewhere on the path to getaddrinfo.
comment:4 Changed 5 years ago by chris_kohlhoff
comment:6 Changed 5 years ago by chris_kohlhoff
Problem reproduced and fix tested under FreeBSD 6.0.