NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/52837: getaddrinfo() resolves "127.0.0.1 www.example.com" to 127.0.0.1



>Number:         52837
>Category:       standards
>Synopsis:       getaddrinfo() resolves "127.0.0.1 www.example.com" to 127.0.0.1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 17 15:10:00 +0000 2017
>Originator:     Michael Kaufmann
>Release:        NetBSD-current
>Organization:
>Environment:
NetBSD cubieboard 7.99.71 NetBSD 7.99.71 (CUBIEBOARD) #0: Sat May  6 00:13:25 UTC 2017  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/evbarm/compile/CUBIEBOARD evbarm
>Description:
getaddrinfo() uses inet_aton(), which ignores trailing spaces after numerical IP addresses. This means that getaddrinfo() resolves the hostname "127.0.0.1 www.example.com" to the IP address 127.0.0.1.

This bug is also present in some other operating systems, please see https://github.com/curl/curl/pull/2073
>How-To-Repeat:
Example program that shows the problem:

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  struct addrinfo hints, *infoptr, *p;
  char host[256];
  int result;

  memset(&hints, '\0', sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;

  result = getaddrinfo("127.0.0.1 www.example.com", "443", &hints, &infoptr);
  if (result) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(result));
    exit(1);
  }

  for(p = infoptr; p != NULL; p = p->ai_next) {
    getnameinfo(p->ai_addr, p->ai_addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST);
    puts(host);
  }

  freeaddrinfo(infoptr);
  return 0;
}

>Fix:



Home | Main Index | Thread Index | Old Index