chiark / gitweb /
gnupg2 (2.1.18-8~deb9u1) stretch; urgency=medium
[gnupg2.git] / debian / patches / 0039-dirmngr-Avoid-PTR-lookup-for-hosts-in-a-pool.patch
1 From: Werner Koch <wk@gnupg.org>
2 Date: Wed, 15 Feb 2017 17:03:57 +0100
3 Subject: dirmngr: Avoid PTR lookup for hosts in a pool
4
5 * dirmngr/ks-engine-hkp.c (add_host): Don't to a PTR lookup for hosts
6 in a pool.
7 --
8
9 GnuPG-bug-id: 2928
10 Signed-off-by: Werner Koch <wk@gnupg.org>
11 (cherry picked from commit da2ba20868093e3054d18adc2b1bc56cb23e4ba7)
12 ---
13  dirmngr/ks-engine-hkp.c | 23 ++++++++++++++++++-----
14  1 file changed, 18 insertions(+), 5 deletions(-)
15
16 diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
17 index be8b083..32db4bc 100644
18 --- a/dirmngr/ks-engine-hkp.c
19 +++ b/dirmngr/ks-engine-hkp.c
20 @@ -320,10 +320,17 @@ add_host (const char *name, int is_pool,
21  
22    idx = find_hostinfo (name);
23  
24 -  if (!is_pool && !is_ip_address (name))
25 +  if (is_pool)
26      {
27 -      /* This is a hostname but not a pool.  Use the name
28 -         as given without going through resolve_dns_addr.  */
29 +      /* For a pool immediately convert the address to a string.  */
30 +      tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
31 +                                 (DNS_NUMERICHOST | DNS_WITHBRACKET), &tmphost);
32 +      is_numeric = 1;
33 +    }
34 +  else if (!is_ip_address (name))
35 +    {
36 +      /* This is a hostname.  Use the name as given without going
37 +       * through resolve_dns_addr.  */
38        tmphost = xtrystrdup (name);
39        if (!tmphost)
40          tmperr = gpg_error_from_syserror ();
41 @@ -332,6 +339,10 @@ add_host (const char *name, int is_pool,
42      }
43    else
44      {
45 +      /* Do a PTR lookup on AI.  If a name was not found the function
46 +       * returns the numeric address (with brackets) and we set a flag
47 +       * so that we know that the conversion to a numerical string has
48 +       * already be done.  */
49        tmperr = resolve_dns_addr (ai->addr, ai->addrlen,
50                                   DNS_WITHBRACKET, &tmphost);
51        if (tmphost && is_ip_address (tmphost))
52 @@ -364,8 +375,7 @@ add_host (const char *name, int is_pool,
53  
54        if (tmpidx == -1)
55          {
56 -          log_error ("map_host for '%s' problem: %s - '%s'"
57 -                     " [ignored]\n",
58 +          log_error ("map_host for '%s' problem: %s - '%s' [ignored]\n",
59                       name, strerror (errno), tmphost);
60          }
61        else  /* Set or update the entry. */
62 @@ -375,6 +385,9 @@ add_host (const char *name, int is_pool,
63            if (port)
64              hosttable[tmpidx]->port = port;
65  
66 +          /* If TMPHOST is not yet a numerical value do this now.
67 +           * Note: This is a simple string operations and not a PTR
68 +           * lookup (due to DNS_NUMERICHOST).  */
69            if (!is_numeric)
70              {
71                xfree (tmphost);