This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][BZ #13928] Use minimum ttl value from dns query


Hi,

I missed the case of host queries using getaddrinfo() in my last patch.
I've attached an updated patch with these changes. New ChangeLog below.
Tested with same scenarios as earlier, except that the command now is:

getent ahosts bad.foo.net

instead of:

getent hosts bad.foo.net

Regards,
Siddhesh

2012-03-29  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* resolv/nss_dns/dns-host.c (getanswer_r): Also consider ttl
	from a CNAME entry and return the minimum ttl for the query.
	(gaih_getanswer_slice): Likewise.
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 10aecb8..ed75b10 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2004, 2007-2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2004, 2007-2009, 2010, 2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -744,6 +744,10 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
 
       if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME)
 	{
+	  /* A CNAME could also have a TTL entry.  */
+	  if (ttlp != NULL && ttl < *ttlp)
+	      *ttlp = ttl;
+
 	  if (ap >= &host_data->aliases[MAX_NR_ALIASES - 1])
 	    continue;
 	  n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
@@ -905,7 +909,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
 	    {
 	      register int nn;
 
-	      if (ttlp != NULL)
+	      if (ttlp != NULL && ttl < *ttlp)
 		*ttlp = ttl;
 	      if (canonp != NULL)
 		*canonp = bp;
@@ -1081,6 +1085,11 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
       if (type == T_CNAME)
 	{
 	  char tbuf[MAXDNAME];
+
+	  /* A CNAME could also have a TTL entry.  */
+	  if (ttlp != NULL && ttl < *ttlp)
+	      *ttlp = ttl;
+
 	  n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
 	  if (__builtin_expect (n < 0 || res_hnok (tbuf) == 0, 0))
 	    {
@@ -1161,7 +1170,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
 
       if (*firstp)
 	{
-	  if (ttlp != NULL)
+	  if (ttlp != NULL && ttl < *ttlp)
 	    *ttlp = ttl;
 
 	  (*pat)->name = canon ?: h_name;
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]