Modify

Ticket #4690 (closed Bugs: fixed)

Opened 4 years ago

Last modified 4 years ago

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

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

Change History

Changed 4 years ago by Gennady Proskurin <gpr@…>

comment:1 Changed 4 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 4 years ago by Gennady Proskurin <gprspb@…>

  • Status changed from closed to reopened
  • Resolution worksforme deleted

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.

Changed 4 years ago by Gennady Proskurin <gprspb@…>

gdb debug session

comment:3 Changed 4 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 4 years ago by chris_kohlhoff

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

comment:5 Changed 4 years ago by chris_kohlhoff

Can you please try changeset [66022].

comment:6 Changed 4 years ago by chris_kohlhoff

Problem reproduced and fix tested under FreeBSD 6.0.

comment:7 Changed 4 years ago by chris_kohlhoff

  • Status changed from reopened to closed
  • Resolution set to fixed

Fixed in [66080].

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.