diff options
author | Andreas Schwab <schwab@suse.de> | 2013-10-15 10:21:13 +0200 |
---|---|---|
committer | Andreas Schwab <schwab@suse.de> | 2013-10-17 16:34:27 +0200 |
commit | b957ced8890a4438c8efe2c15e5abf4e327f25cf (patch) | |
tree | 682df3211c5d75e71af38da8c539b439a4819152 /sysdeps/posix/getaddrinfo.c | |
parent | c5d5d574cbfa96d0f6c1db24d1e072c472627e41 (diff) | |
download | glibc-b957ced8890a4438c8efe2c15e5abf4e327f25cf.tar.gz glibc-b957ced8890a4438c8efe2c15e5abf4e327f25cf.tar.xz glibc-b957ced8890a4438c8efe2c15e5abf4e327f25cf.zip |
Don't use gethostbyaddr to determine canonical name
Diffstat (limited to 'sysdeps/posix/getaddrinfo.c')
-rw-r--r-- | sysdeps/posix/getaddrinfo.c | 89 |
1 files changed, 11 insertions, 78 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 170ad8c400..0f4b88514f 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -564,10 +564,11 @@ gaih_inet (const char *name, const struct gaih_service *service, int no_more; int old_res_options; - /* If we do not have to look for IPv6 addresses, use - the simple, old functions, which do not support - IPv6 scope ids. */ - if (req->ai_family == AF_INET) + /* If we do not have to look for IPv6 addresses or the canonical + name, use the simple, old functions, which do not support + IPv6 scope ids, nor retrieving the canonical name. */ + if (req->ai_family == AF_INET + && (req->ai_flags & AI_CANONNAME) == 0) { /* Allocate additional room for struct host_data. */ size_t tmpbuflen = (512 + MAX_NR_ALIASES * sizeof(char*) @@ -1009,8 +1010,9 @@ gaih_inet (const char *name, const struct gaih_service *service, canon = s; else { - /* Set to name now to avoid using - gethostbyaddr. */ + /* If the canonical name cannot be + determined, use the passed in + string. */ if (malloc_canonbuf) { free (canonbuf); @@ -1125,70 +1127,10 @@ gaih_inet (const char *name, const struct gaih_service *service, /* Only the first entry gets the canonical name. */ if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0) { - char *tmpbuf2 = NULL; - bool malloc_tmpbuf2 = false; - if (canon == NULL) - { - struct hostent *h = NULL; - int herrno; - struct hostent th; - /* Add room for struct host_data. */ - size_t tmpbuf2len = (512 + (MAX_NR_ALIASES+MAX_NR_ADDRS+1) - * sizeof(char*) + 16 * sizeof(char)); - - do - { - if (__libc_use_alloca (alloca_used + 2 * tmpbuf2len)) - tmpbuf2 = extend_alloca_account (tmpbuf2, tmpbuf2len, - tmpbuf2len * 2, - alloca_used); - else - { - char *newp = realloc (malloc_tmpbuf2 ? tmpbuf2 : NULL, - 2 * tmpbuf2len); - if (newp == NULL) - { - if (malloc_tmpbuf2) - free (tmpbuf2); - result = -EAI_MEMORY; - goto free_and_return; - } - - tmpbuf2 = newp; - tmpbuf2len = 2 * tmpbuf2len; - malloc_tmpbuf2 = true; - } - - rc = __gethostbyaddr_r (at2->addr, - ((at2->family == AF_INET6) - ? sizeof (struct in6_addr) - : sizeof (struct in_addr)), - at2->family, &th, tmpbuf2, - tmpbuf2len, &h, &herrno); - } - while (rc == ERANGE && herrno == NETDB_INTERNAL); - - if (rc != 0 && herrno == NETDB_INTERNAL) - { - if (malloc_tmpbuf2) - free (tmpbuf2); - - __set_h_errno (herrno); - result = -EAI_SYSTEM; - goto free_and_return; - } - - if (h != NULL) - canon = h->h_name; - else - { - assert (orig_name != NULL); - /* If the canonical name cannot be determined, use - the passed in string. */ - canon = orig_name; - } - } + /* If the canonical name cannot be determined, use + the passed in string. */ + canon = orig_name; #ifdef HAVE_LIBIDN if (req->ai_flags & AI_CANONIDN) @@ -1203,9 +1145,6 @@ gaih_inet (const char *name, const struct gaih_service *service, int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags); if (rc != IDNA_SUCCESS) { - if (malloc_tmpbuf2) - free (tmpbuf2); - if (rc == IDNA_MALLOC_ERROR) result = -EAI_MEMORY; else if (rc == IDNA_DLOPEN_ERROR) @@ -1235,17 +1174,11 @@ gaih_inet (const char *name, const struct gaih_service *service, canon = strdup (canon); if (canon == NULL) { - if (malloc_tmpbuf2) - free (tmpbuf2); - result = -EAI_MEMORY; goto free_and_return; } } } - - if (malloc_tmpbuf2) - free (tmpbuf2); } family = at2->family; |