Bug 1059122 - libc getaddrinfo fails for hostname containing only decimal digits
Summary: libc getaddrinfo fails for hostname containing only decimal digits
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 20
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Carlos O'Donell
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-01-29 08:32 UTC by Ariel Glenn
Modified: 2016-11-24 12:40 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2014-01-31 12:28:35 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
test-getaddrinfo.c does what the name says (922 bytes, text/x-csrc)
2014-01-29 08:32 UTC, Ariel Glenn
no flags Details

Description Ariel Glenn 2014-01-29 08:32:34 UTC
Created attachment 856951 [details]
test-getaddrinfo.c   does what the name says

Description of problem:

getaddrinfo fails with an error for a hostname that consists only of digits 0-9.  Docker for example generates such hostnames for its containers (it generates hex strings but some of those turn out to contain only 0-9).

Version-Release number of selected component (if applicable):

glibc-2.18-11.fc20.x86_64

Steps to Reproduce:

1. add the lines to /etc/hosts:
172.17.10.53    blobber
172.17.10.54    836937931829

2. compile the attached c program (just sets up a struct addrinfo and calls getaddrinfo() and run it

Actual results:

$ ./test-getaddrinfo 172.17.10.53 80
Success!
$ ./test-getaddrinfo blobber 80
Success!
$ ./test-getaddrinfo 172.17.10.54 80
Success!
$ ./test-getaddrinfo 836937931829 80
getaddrinfo: Name or service not known

Expected results:
success for all four runs

Additional info:
this also breaks getaddrinfo() in python.

Comment 1 Siddhesh Poyarekar 2014-01-31 12:28:35 UTC
Numeric arguments are considered to be IP addresses and not valid host names.  The amendment to RFC 952 (with RFC 1123) may allow for all-numeric host names, but that conflicts with this documented documented IP address format:

http://pubs.opengroup.org/onlinepubs/009695399/functions/inet_addr.html

There is an explicit note in RFC 1123:

           If a dotted-decimal number can be entered without such
           identifying delimiters, then a full syntactic check must be
           made, because a segment of a host domain name is now allowed
           to begin with a digit and could legally be entirely numeric
           (see Section 6.1.2.4).  However, a valid host name can never
           have the dotted-decimal form #.#.#.#, since at least the
           highest-level component label will be alphabetic.

which technically allows us to look at a number as an IP address and if that fails, fall back to a hostname lookup.  This would be very confusing behaviour though, so I don't think it's a good idea to change the current state of the art.

So to conclude, please don't use only numeric hostnames.


Note You need to log in before you can comment on or make changes to this bug.