]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix various bugs reported by valgrind --tool=memcheck (#46978)
authorMukund Sivaraman <muks@isc.org>
Fri, 12 Jan 2018 19:01:30 +0000 (00:31 +0530)
committerMukund Sivaraman <muks@isc.org>
Sat, 13 Jan 2018 06:17:46 +0000 (11:47 +0530)
(cherry picked from commit f96133826e3f70efea237b7fe6a47a45a35a6ab0)
(cherry picked from commit 0374e1c3fdc13a20648d9c9de5601ad042e6044d)

12 files changed:
CHANGES
bin/named/client.c
bin/named/include/named/client.h
bin/named/notify.c
lib/dns/include/dns/nta.h
lib/dns/include/dns/zone.h
lib/dns/nta.c
lib/dns/rdataslab.c
lib/dns/resolver.c
lib/dns/win32/libdns.def.in
lib/dns/zone.c
lib/isc/unix/socket.c

diff --git a/CHANGES b/CHANGES
index eb5f84fd645835da431a60f0d5293f6558918c3c..06016bb955a4190248ad6a13d4f73a7ed200ffa3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+4863.  [bug]           Fix various other bugs reported by Valgrind's
+                       memcheck tool. [RT #46978]
+
 4862.  [bug]           The rdata flags for RRSIG were not being properly set
                        when constructing a rdataslab. [RT #46978]
 
index a51a14fd16a1d51a9ab38d9381b85b6b323e6807..7cebf9a6ae988adee47cffdba7de6ad26dc65abf 100644 (file)
@@ -2597,6 +2597,8 @@ client_request(isc_task_t *task, isc_event_t *event) {
                }
        }
 
+       isc_sockaddr_fromnetaddr(&client->destsockaddr, &client->destaddr, 0);
+
        /*
         * Find a view that matches the client's source address.
         */
@@ -3646,6 +3648,11 @@ ns_client_getsockaddr(ns_client_t *client) {
        return (&client->peeraddr);
 }
 
+isc_sockaddr_t *
+ns_client_getdestaddr(ns_client_t *client) {
+       return (&client->destsockaddr);
+}
+
 isc_result_t
 ns_client_checkaclsilent(ns_client_t *client, isc_netaddr_t *netaddr,
                         dns_acl_t *acl, isc_boolean_t default_allow)
index eceac7fe5eeecbf2cb131bdec1882721542f28f1..3d9655d6ae46325c5b666bb8be613e78f19fd467 100644 (file)
@@ -134,6 +134,7 @@ struct ns_client {
        isc_sockaddr_t          peeraddr;
        isc_boolean_t           peeraddr_valid;
        isc_netaddr_t           destaddr;
+       isc_sockaddr_t          destsockaddr;
 
        isc_netaddr_t           ecs_addr;       /*%< EDNS client subnet */
        isc_uint8_t             ecs_addrlen;
@@ -305,6 +306,13 @@ ns_client_getsockaddr(ns_client_t *client);
  * currently being processed.
  */
 
+isc_sockaddr_t *
+ns_client_getdestaddr(ns_client_t *client);
+/*%<
+ * Get the destination address (server) for the request that is
+ * currently being processed.
+ */
+
 isc_result_t
 ns_client_checkaclsilent(ns_client_t *client, isc_netaddr_t *netaddr,
                         dns_acl_t *acl, isc_boolean_t default_allow);
index dd615bf7d6533a84db06e71846331fbb31d922aa..f0aed1cb95a296016b159574d3c32b29f0ba5c7a 100644 (file)
@@ -81,7 +81,8 @@ ns_notify_start(ns_client_t *client) {
        if (result != ISC_R_SUCCESS) {
                notify_log(client, ISC_LOG_NOTICE,
                           "notify question section empty");
-               goto formerr;
+               result = DNS_R_FORMERR;
+               goto done;
        }
 
        /*
@@ -93,7 +94,8 @@ ns_notify_start(ns_client_t *client) {
        if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) {
                notify_log(client, ISC_LOG_NOTICE,
                           "notify question section contains multiple RRs");
-               goto formerr;
+               result = DNS_R_FORMERR;
+               goto done;
        }
 
        /* The zone section must have exactly one name. */
@@ -101,14 +103,16 @@ ns_notify_start(ns_client_t *client) {
        if (result != ISC_R_NOMORE) {
                notify_log(client, ISC_LOG_NOTICE,
                           "notify question section contains multiple RRs");
-               goto formerr;
+               result = DNS_R_FORMERR;
+               goto done;
        }
 
        /* The one rdataset must be an SOA. */
        if (zone_rdataset->type != dns_rdatatype_soa) {
                notify_log(client, ISC_LOG_NOTICE,
                           "notify question section contains no SOA");
-               goto formerr;
+               result = DNS_R_FORMERR;
+               goto done;
        }
 
        tsigkey = dns_message_gettsigkey(request);
@@ -127,38 +131,33 @@ ns_notify_start(ns_client_t *client) {
                }
        } else
                tsigbuf[0] = '\0';
+
        dns_name_format(zonename, namebuf, sizeof(namebuf));
-       result = dns_zt_find(client->view->zonetable, zonename, 0, NULL,
-                            &zone);
-       if (result != ISC_R_SUCCESS)
-               goto notauth;
-
-       switch (dns_zone_gettype(zone)) {
-       case dns_zone_master:
-       case dns_zone_slave:
-       case dns_zone_stub:     /* Allow dialup passive to work. */
-               notify_log(client, ISC_LOG_INFO,
-                          "received notify for zone '%s'%s", namebuf, tsigbuf);
-               respond(client, dns_zone_notifyreceive(zone,
-                       ns_client_getsockaddr(client), request));
-               break;
-       default:
-               goto notauth;
+       result = dns_zt_find(client->view->zonetable, zonename, 0, NULL, &zone);
+       if (result == ISC_R_SUCCESS) {
+               dns_zonetype_t zonetype = dns_zone_gettype(zone);
+
+               if ((zonetype == dns_zone_master) ||
+                   (zonetype == dns_zone_slave) ||
+                   (zonetype == dns_zone_stub))
+               {
+                       isc_sockaddr_t *from = ns_client_getsockaddr(client);
+                       isc_sockaddr_t *to = ns_client_getdestaddr(client);
+                       notify_log(client, ISC_LOG_INFO,
+                                  "received notify for zone '%s'%s",
+                                  namebuf, tsigbuf);
+                       result = dns_zone_notifyreceive2(zone, from, to,
+                                                        request);
+                       goto done;
+               }
        }
-       dns_zone_detach(&zone);
-       return;
 
- notauth:
        notify_log(client, ISC_LOG_NOTICE,
                   "received notify for zone '%s'%s: not authoritative",
                   namebuf, tsigbuf);
        result = DNS_R_NOTAUTH;
-       goto failure;
-
- formerr:
-       result = DNS_R_FORMERR;
 
failure:
done:
        if (zone != NULL)
                dns_zone_detach(&zone);
        respond(client, result);
index 3c96c1ff0d5e3e4ada71dbadbcaa4b16be0617f2..1733dd30fac50db59f6edecff8f488356001bd9f 100644 (file)
@@ -41,7 +41,6 @@ struct dns_ntatable {
        unsigned int            magic;
        dns_view_t              *view;
        isc_rwlock_t            rwlock;
-       isc_uint32_t            recheck;
        isc_taskmgr_t           *taskmgr;
        isc_timermgr_t          *timermgr;
        isc_task_t              *task;
index acec5ad4870f748a4589d7367634c55cdd2165a3..310b62b91b16453e3f716a953ba7487b938ecec4 100644 (file)
@@ -1264,6 +1264,9 @@ dns_zone_getjournalsize(dns_zone_t *zone);
 isc_result_t
 dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from,
                       dns_message_t *msg);
+isc_result_t
+dns_zone_notifyreceive2(dns_zone_t *zone, isc_sockaddr_t *from,
+                       isc_sockaddr_t *to, dns_message_t *msg);
 /*%<
  *     Tell the zone that it has received a NOTIFY message from another
  *     server.  This may cause some zone maintenance activity to occur.
index 66527ff5f0e847d694821a8aa4b668cab8cc5e8b..ebd363feca063f20f6d94d2f833026eee0cc0f32 100644 (file)
@@ -238,7 +238,7 @@ fetch_done(isc_task_t *task, isc_event_t *event) {
         * If we're expiring before the next recheck, we might
         * as well stop the timer now.
         */
-       if (nta->timer != NULL && nta->expiry - now < ntatable->recheck)
+       if (nta->timer != NULL && nta->expiry - now < view->nta_recheck)
                (void) isc_timer_reset(nta->timer, isc_timertype_inactive,
                                       NULL, NULL, ISC_TRUE);
        nta_detach(view->mctx, &nta);
index fb0076fcf33d4e71c7d473ec14bac7a8dbb9c00e..23857713237db6f39e7cb0f24ca0cce462edd2cb 100644 (file)
@@ -288,7 +288,9 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
        region->base = rawbuf;
        region->length = buflen;
 
+       memset(rawbuf, 0, buflen);
        rawbuf += reservelen;
+
 #if DNS_RDATASET_FIXED
        offsetbase = rawbuf;
 #endif
index 8bfb6619f53bf5e6f33ad09525f71d79f90747a8..2109afffcb5745af68756532dec001309b2cffa8 100644 (file)
@@ -1670,6 +1670,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
        query->sends = 0;
        query->connects = 0;
        query->dscp = addrinfo->dscp;
+       query->udpsize = 0;
        /*
         * Note that the caller MUST guarantee that 'addrinfo' will remain
         * valid until this query is canceled.
index 457b4a91c9974b43a7c7281c47d7f1c654eddc32..21b4b109918534767103cc0a97951265a27f098f 100644 (file)
@@ -1257,6 +1257,7 @@ dns_zone_nameonly
 dns_zone_next
 dns_zone_notify
 dns_zone_notifyreceive
+dns_zone_notifyreceive2
 dns_zone_nscheck
 dns_zone_refresh
 dns_zone_rekey
index 966f52feac6c0ec66e9404a18e2c966c4a02fc9c..c04e807c111625625df6cb31d41a85e4de3c0db4 100644 (file)
@@ -1064,6 +1064,7 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
        zone->rss_event = NULL;
        zone->rss_state = NULL;
        zone->updatemethod = dns_updatemethod_increment;
+       zone->maxrecords = 0U;
 
        zone->magic = ZONE_MAGIC;
 
@@ -13070,6 +13071,13 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags,
 isc_result_t
 dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from,
                       dns_message_t *msg)
+{
+       return (dns_zone_notifyreceive2(zone, from, NULL, msg));
+}
+
+isc_result_t
+dns_zone_notifyreceive2(dns_zone_t *zone, isc_sockaddr_t *from,
+                       isc_sockaddr_t *to, dns_message_t *msg)
 {
        unsigned int i;
        dns_rdata_soa_t soa;
@@ -13079,7 +13087,6 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from,
        char fromtext[ISC_SOCKADDR_FORMATSIZE];
        int match = 0;
        isc_netaddr_t netaddr;
-       isc_sockaddr_t local, remote;
        isc_uint32_t serial = 0;
        isc_boolean_t have_serial = ISC_FALSE;
        dns_tsigkey_t *tsigkey;
@@ -13115,7 +13122,7 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from,
        LOCK_ZONE(zone);
        INSIST(zone != zone->raw);
        if (inline_secure(zone)) {
-               result = dns_zone_notifyreceive(zone->raw, from, msg);
+               result = dns_zone_notifyreceive2(zone->raw, from, to, msg);
                UNLOCK_ZONE(zone);
                return (result);
        }
@@ -13259,10 +13266,11 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from,
                dns_zone_log(zone, ISC_LOG_INFO, "notify from %s: no serial",
                             fromtext);
        zone->notifyfrom = *from;
-       remote = zone->masteraddr;
-       local = zone->sourceaddr;
        UNLOCK_ZONE(zone);
-       dns_zonemgr_unreachabledel(zone->zmgr, &remote, &local);
+
+       if (to != NULL) {
+               dns_zonemgr_unreachabledel(zone->zmgr, from, to);
+       }
        dns_zone_refresh(zone);
        return (ISC_R_SUCCESS);
 }
@@ -18955,6 +18963,7 @@ dns_zone_setnsec3param(dns_zone_t *zone, isc_uint8_t hash, isc_uint8_t flags,
                dns_nsec3param_toprivate(&nrdata, &prdata, zone->privatetype,
                                         np->data, sizeof(np->data));
                np->length = prdata.length;
+               np->nsec = ISC_FALSE;
        }
 
        zone_iattach(zone, &dummy);
index 2d5377fcc8470cd62eecfc74fb7a8582deaae615..a7b4657457ab8aeae4abe02d509273775b4901e7 100644 (file)
@@ -1449,6 +1449,9 @@ build_msghdr_send(isc__socket_t *sock, isc_socketevent_t *dev,
 #endif
 
        memset(msg, 0, sizeof(*msg));
+       if (sock->sendcmsgbuflen != 0U) {
+               memset(sock->sendcmsgbuf, 0, sock->sendcmsgbuflen);
+       }
 
        if (!sock->connected) {
                msg->msg_name = (void *)&dev->address.type.sa;