Skip to content

Commit

Permalink
Avoid duplicate DNS requests if answer is longer than a implementation
Browse files Browse the repository at this point in the history
limit

        [BZ #14307]
        * sysdeps/posix/getaddrinfo.c (gaih_inet): Increase the size of
        the temporary buffer used to invoke __gethostbyname2_r,
        __gethostbyaddr_r and gethostbyname4_r to make room for struct
        host_data / struct gaih_addrtuple.
        * resolv/nss_dns/dns-host.c (global scope): Move definition of
        implementation constants MAX_NR_ALIASES and MAX_NR_ADDRS to
        header file nss/nsswitch.h.
        * nss/nsswitch.h (global scope): Add definition of implementation
        constants MAX_NR_ALIASES and MAX_NR_ADDRS (moved from
        resolv/nss_dns/dns-host.c).
  • Loading branch information
Jeroen van Bemmel authored and Siddhesh Poyarekar committed Jul 12, 2012
1 parent a766fb4 commit 7b6e99b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2012-07-12 Jeroen van Bemmel <jvb127@gmail.com>

[BZ #14307]
* sysdeps/posix/getaddrinfo.c (gaih_inet): Increase the size of
the temporary buffer used to invoke __gethostbyname2_r,
__gethostbyaddr_r and gethostbyname4_r to make room for struct
host_data / struct gaih_addrtuple.
* resolv/nss_dns/dns-host.c (global scope): Move definition of
implementation constants MAX_NR_ALIASES and MAX_NR_ADDRS to
header file nss/nsswitch.h.
* nss/nsswitch.h (global scope): Add definition of implementation
constants MAX_NR_ALIASES and MAX_NR_ADDRS (moved from
resolv/nss_dns/dns-host.c).

2012-07-11 Andreas Jaeger <aj@suse.de>

* po/fr.po: Update from translation team.
Expand Down
7 changes: 5 additions & 2 deletions nss/nsswitch.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* Copyright (C) 1996-1999,2001,2002,2003,2004,2007,2010,2011
Free Software Foundation, Inc.
/* Copyright (C) 1996-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -198,4 +197,8 @@ extern int __nss_hostname_digits_dots (const char *name,
int *h_errnop);
libc_hidden_proto (__nss_hostname_digits_dots)

/* Maximum number of aliases we allow. */
#define MAX_NR_ALIASES 48
#define MAX_NR_ADDRS 48

#endif /* nsswitch.h */
4 changes: 0 additions & 4 deletions resolv/nss_dns/dns-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@

#define RESOLVSORT

/* Maximum number of aliases we allow. */
#define MAX_NR_ALIASES 48
#define MAX_NR_ADDRS 48

#if PACKETSZ > 65536
# define MAXPACKET PACKETSZ
#else
Expand Down
10 changes: 7 additions & 3 deletions sysdeps/posix/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
IPv6 scope ids. */
if (req->ai_family == AF_INET)
{
size_t tmpbuflen = 512;
/* Allocate additional room for struct host_data. */
size_t tmpbuflen = (512 + MAX_NR_ALIASES * sizeof(char*)
+ 16 * sizeof(char));
assert (tmpbuf == NULL);
tmpbuf = alloca_account (tmpbuflen, alloca_used);
int rc;
Expand Down Expand Up @@ -811,7 +813,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
old_res_options = _res.options;
_res.options &= ~RES_USE_INET6;

size_t tmpbuflen = 1024;
size_t tmpbuflen = 1024 + sizeof(struct gaih_addrtuple);
malloc_tmpbuf = !__libc_use_alloca (alloca_used + tmpbuflen);
assert (tmpbuf == NULL);
if (!malloc_tmpbuf)
Expand Down Expand Up @@ -1113,7 +1115,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
struct hostent *h = NULL;
int herrno;
struct hostent th;
size_t tmpbuf2len = 512;
/* Add room for struct host_data. */
size_t tmpbuf2len = (512 + (MAX_NR_ALIASES+MAX_NR_ADDRS+1)
* sizeof(char*) + 16 * sizeof(char));

do
{
Expand Down

0 comments on commit 7b6e99b

Please sign in to comment.