]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
always obtain write lock when updating version->{records,bytes}
authorMark Andrews <marka@isc.org>
Mon, 18 Nov 2019 03:07:18 +0000 (14:07 +1100)
committerOndřej Surý <ondrej@isc.org>
Tue, 19 Nov 2019 16:17:51 +0000 (00:17 +0800)
lib/dns/rbtdb.c

index 9ac0cb8d1a49ef1feffe7d8936651b339d875fc2..0a2b62ec79d84715636ce7b7c21fe9cf3931d39c 100644 (file)
@@ -5751,6 +5751,7 @@ update_recordsandbytes(bool add, rbtdb_version_t *rbtversion,
        unsigned char *hdr = (unsigned char *)header;
        size_t hdrsize = sizeof (*header);
 
+       RWLOCK(&rbtversion->rwlock, isc_rwlocktype_write);
        if (add) {
                rbtversion->records += dns_rdataslab_count(hdr, hdrsize);
                rbtversion->bytes += dns_rdataslab_size(hdr, hdrsize);
@@ -5758,6 +5759,7 @@ update_recordsandbytes(bool add, rbtdb_version_t *rbtversion,
                rbtversion->records -= dns_rdataslab_count(hdr, hdrsize);
                rbtversion->bytes -= dns_rdataslab_size(hdr, hdrsize);
        }
+       RWUNLOCK(&rbtversion->rwlock, isc_rwlocktype_write);
 }
 
 static isc_result_t
@@ -6144,12 +6146,8 @@ add32(dns_rbtdb_t *rbtdb, dns_rbtnode_t *rbtnode, rbtdb_version_t *rbtversion,
                                rbtnode->data = newheader;
                        newheader->next = topheader->next;
                        if (rbtversion != NULL && !header_nx) {
-                               RWLOCK(&rbtversion->rwlock,
-                                      isc_rwlocktype_write);
                                update_recordsandbytes(false, rbtversion,
                                                       header);
-                               RWUNLOCK(&rbtversion->rwlock,
-                                        isc_rwlocktype_write);
                        }
                        free_rdataset(rbtdb, rbtdb->common.mctx, header);
                } else {
@@ -6199,12 +6197,8 @@ add32(dns_rbtdb_t *rbtdb, dns_rbtnode_t *rbtnode, rbtdb_version_t *rbtversion,
                                }
                        }
                        if (rbtversion != NULL && !header_nx) {
-                               RWLOCK(&rbtversion->rwlock,
-                                      isc_rwlocktype_write);
                                update_recordsandbytes(false, rbtversion,
                                                       header);
-                               RWUNLOCK(&rbtversion->rwlock,
-                                        isc_rwlocktype_write);
                        }
                }
        } else {
@@ -6280,9 +6274,7 @@ add32(dns_rbtdb_t *rbtdb, dns_rbtnode_t *rbtnode, rbtdb_version_t *rbtversion,
        }
 
        if (rbtversion != NULL && !newheader_nx) {
-               RWLOCK(&rbtversion->rwlock, isc_rwlocktype_write);
                update_recordsandbytes(true, rbtversion, newheader);
-               RWUNLOCK(&rbtversion->rwlock, isc_rwlocktype_write);
        }
 
        /*
@@ -7091,8 +7083,11 @@ rbt_datafixer(dns_rbtnode_t *rbtnode, void *base, size_t filesize,
                unsigned char *p = (unsigned char *) header;
                size_t size = dns_rdataslab_size(p, sizeof(*header));
                unsigned int count = dns_rdataslab_count(p, sizeof(*header));;
+               RWLOCK(&rbtdb->current_version->rwlock, isc_rwlocktype_write);
                rbtdb->current_version->records += count;
                rbtdb->current_version->bytes += size;
+               RWUNLOCK(&rbtdb->current_version->rwlock,
+                        isc_rwlocktype_write);
                isc_crc64_update(crc, p, size);
 #ifdef DEBUG
                hexdump("hashing header", p, sizeof(rdatasetheader_t));