arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1673465-5.patch

147e83
commit 6ca53a2453598804a2559a548a08424fca96434a
147e83
Author: Florian Weimer <fweimer@redhat.com>
147e83
Date:   Mon Jan 21 09:26:41 2019 +0100
147e83
147e83
    resolv: Do not send queries for non-host-names in nss_dns [BZ #24112]
147e83
    
147e83
    Before this commit, nss_dns would send a query which did not contain a
147e83
    host name as the query name (such as invalid\032name.example.com) and
147e83
    then reject the answer in getanswer_r and gaih_getanswer_slice, using
147e83
    a check based on res_hnok.  With this commit, no query is sent, and a
147e83
    host-not-found error is returned to NSS without network interaction.
147e83
147e83
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
147e83
index 1e85e4f08ffc8600..e697d9103797341b 100644
147e83
--- a/resolv/nss_dns/dns-host.c
147e83
+++ b/resolv/nss_dns/dns-host.c
147e83
@@ -273,11 +273,26 @@ gethostbyname3_context (struct resolv_context *ctx,
147e83
   return status;
147e83
 }
147e83
 
147e83
+/* Verify that the name looks like a host name.  There is no point in
147e83
+   sending a query which will not produce a usable name in the
147e83
+   response.  */
147e83
+static enum nss_status
147e83
+check_name (const char *name, int *h_errnop)
147e83
+{
147e83
+  if (res_hnok (name))
147e83
+    return NSS_STATUS_SUCCESS;
147e83
+  *h_errnop = HOST_NOT_FOUND;
147e83
+  return NSS_STATUS_NOTFOUND;
147e83
+}
147e83
+
147e83
 enum nss_status
147e83
 _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
147e83
 			   char *buffer, size_t buflen, int *errnop,
147e83
 			   int *h_errnop)
147e83
 {
147e83
+  enum nss_status status = check_name (name, h_errnop);
147e83
+  if (status != NSS_STATUS_SUCCESS)
147e83
+    return status;
147e83
   return _nss_dns_gethostbyname3_r (name, af, result, buffer, buflen, errnop,
147e83
 				    h_errnop, NULL, NULL);
147e83
 }
147e83
@@ -288,6 +303,9 @@ _nss_dns_gethostbyname_r (const char *name, struct hostent *result,
147e83
 			  char *buffer, size_t buflen, int *errnop,
147e83
 			  int *h_errnop)
147e83
 {
147e83
+  enum nss_status status = check_name (name, h_errnop);
147e83
+  if (status != NSS_STATUS_SUCCESS)
147e83
+    return status;
147e83
   struct resolv_context *ctx = __resolv_context_get ();
147e83
   if (ctx == NULL)
147e83
     {
147e83
@@ -295,7 +313,7 @@ _nss_dns_gethostbyname_r (const char *name, struct hostent *result,
147e83
       *h_errnop = NETDB_INTERNAL;
147e83
       return NSS_STATUS_UNAVAIL;
147e83
     }
147e83
-  enum nss_status status = NSS_STATUS_NOTFOUND;
147e83
+  status = NSS_STATUS_NOTFOUND;
147e83
   if (res_use_inet6 ())
147e83
     status = gethostbyname3_context (ctx, name, AF_INET6, result, buffer,
147e83
 				     buflen, errnop, h_errnop, NULL, NULL);
147e83
@@ -312,6 +330,9 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
147e83
 			   char *buffer, size_t buflen, int *errnop,
147e83
 			   int *herrnop, int32_t *ttlp)
147e83
 {
147e83
+  enum nss_status status = check_name (name, herrnop);
147e83
+  if (status != NSS_STATUS_SUCCESS)
147e83
+    return status;
147e83
   struct resolv_context *ctx = __resolv_context_get ();
147e83
   if (ctx == NULL)
147e83
     {
147e83
@@ -346,7 +367,6 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
147e83
   int ans2p_malloced = 0;
147e83
 
147e83
   int olderr = errno;
147e83
-  enum nss_status status;
147e83
   int n = __res_context_search (ctx, name, C_IN, T_QUERY_A_AND_AAAA,
147e83
 				host_buffer.buf->buf, 2048, &host_buffer.ptr,
147e83
 				&ans2p, &nans2p, &resplen2, &ans2p_malloced);