Opened 12 years ago

Closed 12 years ago

#4690 closed Bugs (fixed)

boost::asio::ip::tcp::resolver fails to resolve query if service_name is empty

Reported by: Gennady Proskurin <gpr@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

Documentation: http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/reference/ip__basic_resolver_query/basic_resolver_query/overload3.html

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 (2)

resolv.cc (697 bytes ) - added by Gennady Proskurin <gpr@…> 12 years ago.
resolv.gdb (6.9 KB ) - added by Gennady Proskurin <gprspb@…> 12 years ago.
gdb debug session

Download all attachments as: .zip

Change History (9)

by Gennady Proskurin <gpr@…>, 12 years ago

Attachment: resolv.cc added

comment:1 by chris_kohlhoff, 12 years ago

Resolution: worksforme
Status: newclosed

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 by Gennady Proskurin <gprspb@…>, 12 years ago

Resolution: worksforme
Status: closedreopened

gdb output of my program attached This is FreeBSD 9-CURRENT The same result under DragonFlyBSD, and some Linuxes

If it is not obvious to you from gdb output, what's the problem, I can try to look at boost sources when I have time. If you have suggestions how I can get more useful info, please let me know.

by Gennady Proskurin <gprspb@…>, 12 years ago

Attachment: resolv.gdb added

gdb debug session

comment:3 by Gennady Proskurin <gprspb@…>, 12 years ago

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 by chris_kohlhoff, 12 years ago

(In [66022]) Pass NULL for servname rather than empty string, as per POSIX. Refs #4690.

comment:5 by chris_kohlhoff, 12 years ago

Can you please try changeset [66022].

comment:6 by chris_kohlhoff, 12 years ago

Problem reproduced and fix tested under FreeBSD 6.0.

comment:7 by chris_kohlhoff, 12 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in [66080].

Note: See TracTickets for help on using tickets.