public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times
@ 2012-12-30 12:54 psimerda at redhat dot com
  2013-01-11 14:50 ` [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses psimerda at redhat dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2012-12-30 12:54 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

             Bug #: 14990
           Summary: getaddrinfo with servname=NULL returns addresses
                    multiple times
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: normal
          Priority: P2
         Component: network
        AssignedTo: unassigned@sourceware.org
        ReportedBy: psimerda@redhat.com
    Classification: Unclassified


Testing in python:

>>> print(*getaddrinfo ("localhost", None), sep='\n')

Actual result:

(10, 1, 6, '', ('::1', 0, 0, 0))
(10, 2, 17, '', ('::1', 0, 0, 0))
(10, 3, 0, '', ('::1', 0, 0, 0))
(2, 1, 6, '', ('127.0.0.1', 0))
(2, 2, 17, '', ('127.0.0.1', 0))
(2, 3, 0, '', ('127.0.0.1', 0))

Expected result:

(10, 0, 0, '', ('::1', 0, 0, 0))
(2, 0, 0, '', ('127.0.0.1', 0))

POSIX1-2008:

If servname is null, the call shall return network-level addresses for the
specified nodename.

http://pubs.opengroup.org/onlinepubs/009604499/functions/getaddrinfo.html

Filling in the socktype and protocol is IMO not a good idea and returning
duplicate addresses prevents applications from using getaddrinfo for host name
resolution and violates POSIX.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
@ 2013-01-11 14:50 ` psimerda at redhat dot com
  2013-01-11 15:29 ` psimerda at redhat dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2013-01-11 14:50 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

Pavel Šimerda <psimerda at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|getaddrinfo with            |getaddrinfo with
                   |servname=NULL returns       |servname=NULL returns
                   |addresses multiple times    |duplicate addresses

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
  2013-01-11 14:50 ` [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses psimerda at redhat dot com
@ 2013-01-11 15:29 ` psimerda at redhat dot com
  2013-01-11 15:58 ` psimerda at redhat dot com
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2013-01-11 15:29 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

--- Comment #1 from Pavel Šimerda <psimerda at redhat dot com> 2013-01-11 15:28:40 UTC ---
(In reply to comment #0)
> If servname is null, the call shall return network-level addresses for the
> specified nodename.

As a side effect, using socktype and/or protocol when servname=NULL has no
chance to return useful information. These values are there only to supplement
the service option.

But that means SOCK_RAW can be ignored entirely in getaddrinfo().

The only questions is, what should getaddrinfo return when servname is NULL but
socktype and/or protocol is non-zero. There are a couple of options:

1) Fail. This might have impact on existing software.

2) Return zero socktype and zero protocol. This might have impact on existing
software.

3) Return the supplied socktype and protocol.

   a) Without checking.

   b) With a validity check.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
  2013-01-11 14:50 ` [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses psimerda at redhat dot com
  2013-01-11 15:29 ` psimerda at redhat dot com
@ 2013-01-11 15:58 ` psimerda at redhat dot com
  2013-01-11 16:11 ` psimerda at redhat dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2013-01-11 15:58 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

--- Comment #2 from Pavel Šimerda <psimerda at redhat dot com> 2013-01-11 15:58:28 UTC ---
The code for #3a could look something like this:

  if (!servname)
    {
      /* POSIX1-2008: If servname is null, the call shall return network-level
       * addresses for the specified nodename.
       *
       * Example:
       *
       * getaddrinfo ("localhost", NULL, ...) ->
       *   family=AF_INET6 socktype=0 protocol=0 address=::1 port=0
       *   family=AF_INET socktype=0 protocol=0 address=127.0.0.1 port=0
       */
      struct gaih_servtuple *st = malloc (sizeof (struct gaih_servtuple));
      st->next = NULL;
      st->port = 0;
      /* Copy socktype and protocol from the request. This maintains backwards
       * compatibility. Callers should not set socktype and protocol when
       * service is NULL.
       */
      st->socktype = socktype;
      st->protocol = protocol;

      *servtuple = st;
      return 0;
    }

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (2 preceding siblings ...)
  2013-01-11 15:58 ` psimerda at redhat dot com
@ 2013-01-11 16:11 ` psimerda at redhat dot com
  2013-02-24 22:12 ` psimerda at redhat dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2013-01-11 16:11 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

--- Comment #3 from Pavel Šimerda <psimerda at redhat dot com> 2013-01-11 16:11:15 UTC ---
Interesting test results:

>>> getaddrinfo("localhost", None, AF_INET, SOCK_RAW, 0)
[(2, 3, 0, '', ('127.0.0.1', 0)), (2, 3, 0, '', ('127.0.0.1', 0))]
>>> getaddrinfo("www.fedora.cz", None, AF_INET, SOCK_RAW, 0)
[(2, 3, 0, '', ('217.170.99.20', 0))]

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (3 preceding siblings ...)
  2013-01-11 16:11 ` psimerda at redhat dot com
@ 2013-02-24 22:12 ` psimerda at redhat dot com
  2013-03-07  7:28 ` me at ruff dot mobi
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2013-02-24 22:12 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

Pavel Šimerda <psimerda at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at sourceware    |psimerda at redhat dot com
                   |dot org                     |

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (4 preceding siblings ...)
  2013-02-24 22:12 ` psimerda at redhat dot com
@ 2013-03-07  7:28 ` me at ruff dot mobi
  2013-03-07 12:01 ` psimerda at redhat dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: me at ruff dot mobi @ 2013-03-07  7:28 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

Ruslan N. Marchenko <me at ruff dot mobi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |me at ruff dot mobi

--- Comment #4 from Ruslan N. Marchenko <me at ruff dot mobi> 2013-03-07 07:27:40 UTC ---
Hi Pavel,
You probably better look at it from perspective of C call, not python wrapper.
In C it is clear - you're asking for host:service information, providing the
rest as hints.
As such, if service is empty, all hints which should make service more specific
are useless and should be ignored. Hence getaddrinfo(something,null,whatever)
should always return RAW. 
Similarly asking for RAW should ignore service since there's no service for raw
socket.
This is akin to combination of AI_PASSIVE and host NULL - both having similar
mining although using PASSIVE  with non-null host has no sense and PASSIVE flag
is discarded. The difference is that we don't have documented behaviour of
srv=null without RAW.

Anyway, here's what C call returns:

getaddrinfo(localhost,(null),{AF=0,ST=0,FLAGS=0})=0
socket(10, 1, 6)
socket: Success
getnameinfo: Success
 [::1:0] ---> [localhost:(null)]
socket(10, 2, 17)
socket: Success
getnameinfo: Success
 [::1:0] ---> [localhost:(null)]
socket(10, 3, 0)
socket: Protocol not supported
socket(2, 1, 6)
socket: Protocol not supported
getnameinfo: Protocol not supported
 [127.0.0.1:0] ---> [localhost:(null)]
socket(2, 2, 17)
socket: Protocol not supported
getnameinfo: Protocol not supported
 [127.0.0.1:0] ---> [localhost:(null)]
socket(2, 3, 0)
socket: Protocol not supported


I.e. similar results.

This list is returned by gaih_inet() (where all nasty things happen) 
line 375
          /* Neither socket type nor protocol is set.  Return all socket types
             we know about.  */

and successfully passed through deprecation validation and sorting, and not a
piece of code bothered to strip off unneeded results. Will submit patch later.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (5 preceding siblings ...)
  2013-03-07  7:28 ` me at ruff dot mobi
@ 2013-03-07 12:01 ` psimerda at redhat dot com
  2013-03-07 19:29 ` me at ruff dot mobi
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: psimerda at redhat dot com @ 2013-03-07 12:01 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

--- Comment #5 from Pavel Šimerda <psimerda at redhat dot com> 2013-03-07 12:00:27 UTC ---
(In reply to comment #4)
> Hi Pavel,
> You probably better look at it from perspective of C call, not python wrapper.

Please look at it from the perspective of both the POSIX standard and the fact
that getaddrinfo() was designed to replace both gethostbyname().

I don't know why you bring Python into the discussion when the Python interface
is exactly 1:1 to the C interface except the hints are expanded. Python is only
used because it is more convenient for testing.

> you're asking for host:service information, providing the rest as hints.

Correct, unless some of the hints have special meaning on their own.

> As such, if service is empty, all hints which should make service
> more specific are useless and should be ignored.

Correct.

Hence getaddrinfo(something,null,whatever)
> should always return RAW.

Incorrect, in my opinion. I am curious about your explenation taking into
account POSIX and/or real-world use cases. There's IMO no reason to return RAW
unless the caller wants it.

> Similarly asking for RAW should ignore service since there's no service
> for raw socket.

I don't say you are not right here but you contradict yourself, as asking for
RAW is only possible using the hints. Above you asked hints to be always
ignored when service is NULL.

> This is akin to combination of AI_PASSIVE and host NULL - both having similar
> mining although using PASSIVE with non-null host has no sense and PASSIVE flag
> is discarded.

This is wrong. Using AI_PASSIVE with non-null host makes perfect sense even
though AI_PASSIVE is ignored then. You and many others are forgetting that the
flags and the values usually don't come from the same source.

The programmer uses AI_PASSIVE without the knowledge whether the host will be
NULL or non-NULL, which is determined by the user configuration. This is a
convenience tool so that allows the programmer to use the same getaddrinfo()
interface regardless the user input.

> The difference is that we don't have documented behaviour of
> srv=null without RAW.

> Anyway, here's what C call returns:

The Python function is a convenience wrapper over the C call, there's no need
to compare them.

The patch is already available as part of my patchset:

http://git.pavlix.net/gitweb/?p=glibc.git;a=shortlog;h=refs/heads/pavlix/getaddrinfo

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (6 preceding siblings ...)
  2013-03-07 12:01 ` psimerda at redhat dot com
@ 2013-03-07 19:29 ` me at ruff dot mobi
  2013-03-07 19:55 ` me at ruff dot mobi
  2014-06-14  5:24 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: me at ruff dot mobi @ 2013-03-07 19:29 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

--- Comment #6 from Ruslan N. Marchenko <me at ruff dot mobi> 2013-03-07 19:29:01 UTC ---
> Please look at it from the perspective of both the POSIX standard and the fact
> that getaddrinfo() was designed to replace both gethostbyname().

This is the only point I'm looking at it from

>> Hence getaddrinfo(something,null,whatever) should always return RAW.
>Incorrect, in my opinion.

>> Similarly asking for RAW should ignore service since there's no service
>> for raw socket.
> Above you asked hints to be always ignored when service is NULL.
Yes, this is not explicitly written by standard so my common sense is saying
that it's useless to parse socktype when service s null. although one can
always return error for unclear by standard cases.

> Using AI_PASSIVE with non-null host makes perfect sense even 
> though AI_PASSIVE is ignored then.

I think we need to be careful with common sense when dealing with explicitly
stated standard:
http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html
>> qoute >>
The AI_PASSIVE flag shall be ignored if the nodename argument is not null.
<< end quote <<

> You and many others are forgetting that the flags and the values usually don't come from the same source.

I don't, and that the background for my reasoning.

>The Python function is a convenience wrapper over the C call, there's no need
to compare them.

right, my c snippet initially was returning different result so i started this
C part but then i found i was setting socktype at the end. You can disregard
it.

> The patch is already available as part of my patchset:
Glad you care about that. And since getaddrinfo is to be completely revamped
anyway I'm going to propose another solution for passive flag.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (7 preceding siblings ...)
  2013-03-07 19:29 ` me at ruff dot mobi
@ 2013-03-07 19:55 ` me at ruff dot mobi
  2014-06-14  5:24 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: me at ruff dot mobi @ 2013-03-07 19:55 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14990

--- Comment #7 from Ruslan N. Marchenko <me at ruff dot mobi> 2013-03-07 19:55:03 UTC ---
After second read it seems we arguing about the same topic with different
words. I'd better postpone this discussion till weekend, hard to concentrate
after work.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses
  2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
                   ` (8 preceding siblings ...)
  2013-03-07 19:55 ` me at ruff dot mobi
@ 2014-06-14  5:24 ` fweimer at redhat dot com
  9 siblings, 0 replies; 11+ messages in thread
From: fweimer at redhat dot com @ 2014-06-14  5:24 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=14990

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-14  5:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-30 12:54 [Bug network/14990] New: getaddrinfo with servname=NULL returns addresses multiple times psimerda at redhat dot com
2013-01-11 14:50 ` [Bug network/14990] getaddrinfo with servname=NULL returns duplicate addresses psimerda at redhat dot com
2013-01-11 15:29 ` psimerda at redhat dot com
2013-01-11 15:58 ` psimerda at redhat dot com
2013-01-11 16:11 ` psimerda at redhat dot com
2013-02-24 22:12 ` psimerda at redhat dot com
2013-03-07  7:28 ` me at ruff dot mobi
2013-03-07 12:01 ` psimerda at redhat dot com
2013-03-07 19:29 ` me at ruff dot mobi
2013-03-07 19:55 ` me at ruff dot mobi
2014-06-14  5:24 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).