From e8a89905816971554462c58bbc5a396efbf29cfa Mon Sep 17 00:00:00 2001
From: Julien Cristau <jcristau@debian.org>
Date: Sat, 22 May 2010 13:50:49 +0200
Subject: [PATCH 2/5] Don't spuriously ignore CNAMEs after a DNS timeout.

Add patch cherry-picked from upstream git to stop ignoring CNAMEs after
a DNS timeout (closes: #540912).
---
 debian/changelog                                   |    2 +
 debian/patches/00list                              |    1 +
 ...iously-ignore-CNAMEs-after-a-DNS-timeout.dpatch |   45 ++++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)
 create mode 100644 debian/patches/30_Don-t-spuriously-ignore-CNAMEs-after-a-DNS-timeout.dpatch

diff --git a/debian/changelog b/debian/changelog
index 801df11..3868899 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,8 @@ polipo (1.0.4.1-1.1) UNRELEASED; urgency=low
 
   * Delete obsolete /etc/network/if-{up,down}.d and /etc/ppp/ip-{up,down}.d
     scripts (closes: #578684).
+  * Add patch cherry-picked from upstream git to stop ignoring CNAMEs after a
+    DNS timeout (closes: #540912).
 
  -- Julien Cristau <jcristau@debian.org>  Sat, 01 May 2010 17:48:59 +0200
 
diff --git a/debian/patches/00list b/debian/patches/00list
index 5c4af52..c7f6af3 100644
--- a/debian/patches/00list
+++ b/debian/patches/00list
@@ -1,2 +1,3 @@
 10_makefile.dpatch
 20_config.dpatch
+30_Don-t-spuriously-ignore-CNAMEs-after-a-DNS-timeout.dpatch
diff --git a/debian/patches/30_Don-t-spuriously-ignore-CNAMEs-after-a-DNS-timeout.dpatch b/debian/patches/30_Don-t-spuriously-ignore-CNAMEs-after-a-DNS-timeout.dpatch
new file mode 100644
index 0000000..343c74c
--- /dev/null
+++ b/debian/patches/30_Don-t-spuriously-ignore-CNAMEs-after-a-DNS-timeout.dpatch
@@ -0,0 +1,45 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## 30_Don-t-spuriously-ignore-CNAMEs-after-a-DNS-timeout.dpatch by Alan Jenkins
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: Don't spuriously ignore CNAMEs after a DNS timeout
+## DP: cherry-picked from 1144bc9a25fe685bf5a8d18a22d4fa79b9ade75b
+
+@DPATCH@
+
+From 1144bc9a25fe685bf5a8d18a22d4fa79b9ade75b Mon Sep 17 00:00:00 2001
+From: Juliusz Chroboczek <jch@pps.jussieu.fr>
+Date: Tue, 10 Nov 2009 16:48:04 -0800
+Subject: [PATCH] Don't spuriously ignore CNAMEs after a DNS timeout.
+
+Ignore-this: 60fbb7453699ecbff6961bf1622dfb3
+From Alan Jenkins.
+
+darcs-hash:20091111004804-4cc09-0d24709fbdebd5a7bdc5ce01a6a76aab5bc1241c.gz
+---
+ dns.c |    9 +++++++++
+ 1 files changed, 9 insertions(+), 0 deletions(-)
+
+diff --git a/dns.c b/dns.c
+index 8d4ac75..1a5b39b 100644
+--- a/dns.c
++++ b/dns.c
+@@ -1181,6 +1181,15 @@ dnsReplyHandler(int abort, FdEventHandlerPtr event)
+         } else
+             releaseAtom(value);
+     } else if(af == 0) {
++        /* Ignore errors in this case. */
++        if(query->inet4 && query->inet4->length == 0) {
++            releaseAtom(query->inet4);
++            query->inet4 = NULL;
++        }
++        if(query->inet6 && query->inet6->length == 0) {
++            releaseAtom(query->inet6);
++            query->inet6 = NULL;
++        }
+         if(query->inet4 || query->inet6) {
+             do_log(L_WARN, "Host %s has both %s and CNAME -- "
+                    "ignoring CNAME.\n", scrub(query->name->string),
+-- 
+1.7.1
+
-- 
1.7.1

