public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug network/16469] New: getaddrinfo incorrectly accepts two trailing dots
@ 2014-01-20  5:05 nigeltao at golang dot org
  2014-06-13  8:54 ` [Bug network/16469] " fweimer at redhat dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: nigeltao at golang dot org @ 2014-01-20  5:05 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 16469
           Summary: getaddrinfo incorrectly accepts two trailing dots
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: normal
          Priority: P2
         Component: network
          Assignee: unassigned at sourceware dot org
          Reporter: nigeltao at golang dot org

getaddrinfo("www.google.com..", etc) with two trailing dots resolves, but I
expected an error, as "www.google.com.." is not a valid domain name.

"www.google.com." with one trailing dot works as expected, as one trailing dot
means a FQDN. "www.google.com..." with three trailing dots gives a "No address
associated with hostname" error, as expected.

Ubuntu 12.04 "Precise", so glibc 2.15.

--------
/* This example program adapted from
http://en.wikipedia.org/wiki/Getaddrinfo#Example */

/* Note the two trailing dots in the "www.google.com.." hostname! */

#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>

#ifndef   NI_MAXHOST
#define   NI_MAXHOST 1025
#endif

int main(void)
{
    struct addrinfo *result;
    struct addrinfo *res;
    int error;

    error = getaddrinfo("www.google.com..", NULL, NULL, &result);
    if (error != 0)
    {   
        if (error == EAI_SYSTEM)
        {
            perror("getaddrinfo");
        }
        else
        {
            fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
        }   
        exit(EXIT_FAILURE);
    }   

    for (res = result; res != NULL; res = res->ai_next)
    {   
        char hostname[NI_MAXHOST] = "";

        error = getnameinfo(res->ai_addr, res->ai_addrlen, hostname,
NI_MAXHOST, NULL, 0, 0); 
        if (error != 0)
        {
            fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
            continue;
        }
        if (*hostname != '\0')
            printf("hostname: %s\n", hostname);
    }   

    freeaddrinfo(result);
    return 0;
}
--------

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


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

end of thread, other threads:[~2014-11-21  6:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-20  5:05 [Bug network/16469] New: getaddrinfo incorrectly accepts two trailing dots nigeltao at golang dot org
2014-06-13  8:54 ` [Bug network/16469] " fweimer at redhat dot com
2014-09-27 10:40 ` aoliva at sourceware dot org
2014-11-07  9:20 ` cvs-commit at gcc dot gnu.org
2014-11-21  5:42 ` cvs-commit at gcc dot gnu.org
2014-11-21  6:28 ` aoliva at sourceware dot org

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).