[PATCH] Don't require DNS labels to be host names
Andreas Schwab
schwab@redhat.com
Tue Oct 26 12:53:00 GMT 2010
2010-10-26 Andreas Schwab <schwab@redhat.com>
[BZ #12154]
* resolv/nss_dns/dns-host.c (getanswer_r): Don't require DNS
labels to be host names.
(gaih_getanswer_slice): Likewise.
---
resolv/nss_dns/dns-host.c | 42 ++++++++++++++++++++++++++++--------------
1 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 8592183..19f6dab 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -716,7 +716,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
n = -1;
}
- if (__builtin_expect (n < 0 || (*name_ok) (bp) == 0, 0))
+ if (__builtin_expect (n < 0 || res_dnok (bp) == 0, 0))
{
++had_error;
continue;
@@ -746,25 +746,29 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME)
{
- if (ap >= &host_data->aliases[MAX_NR_ALIASES - 1])
- continue;
n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
- if (__builtin_expect (n < 0 || (*name_ok) (tbuf) == 0, 0))
+ if (__builtin_expect (n < 0 || res_dnok (tbuf) == 0, 0))
{
++had_error;
continue;
}
cp += n;
- /* Store alias. */
- *ap++ = bp;
- n = strlen (bp) + 1; /* For the \0. */
- if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
+ /* Ignore aliases that are not valid host names. */
+ if (res_hnok (bp))
{
- ++had_error;
- continue;
+ if (ap >= &host_data->aliases[MAX_NR_ALIASES - 1])
+ continue;
+ /* Store alias. */
+ *ap++ = bp;
+ n = strlen (bp) + 1; /* For the \0. */
+ if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
+ {
+ ++had_error;
+ continue;
+ }
+ bp += n;
+ linebuflen -= n;
}
- bp += n;
- linebuflen -= n;
/* Get canonical name. */
n = strlen (tbuf) + 1; /* For the \0. */
if (__builtin_expect (n > linebuflen, 0))
@@ -892,6 +896,11 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
#endif
case T_A:
case T_AAAA:
+ if (res_hnok (bp) == 0)
+ {
+ had_error++;
+ break;
+ }
if (__builtin_expect (strcasecmp (result->h_name, bp), 0) != 0)
{
syslog (LOG_NOTICE | LOG_AUTH, AskedForGot, result->h_name, bp);
@@ -1045,7 +1054,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
n = -1;
}
- if (__builtin_expect (n < 0 || res_hnok (buffer) == 0, 0))
+ if (__builtin_expect (n < 0 || res_dnok (buffer) == 0, 0))
{
++had_error;
continue;
@@ -1084,7 +1093,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
{
char tbuf[MAXDNAME];
n = dn_expand (answer->buf, end_of_message, cp, tbuf, sizeof tbuf);
- if (__builtin_expect (n < 0 || res_hnok (tbuf) == 0, 0))
+ if (__builtin_expect (n < 0 || res_dnok (tbuf) == 0, 0))
{
++had_error;
continue;
@@ -1163,6 +1172,11 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
if (*firstp)
{
+ if (res_hnok (canon ?: h_name) == 0)
+ {
+ ++had_error;
+ continue;
+ }
if (ttl != 0 && ttlp != NULL)
*ttlp = ttl;
--
1.7.2.3
--
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
More information about the Libc-hacker
mailing list