]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Lock access to 'answer' to silence TSAN
authorMark Andrews <marka@isc.org>
Tue, 19 May 2020 03:25:41 +0000 (13:25 +1000)
committerMark Andrews <marka@isc.org>
Thu, 28 May 2020 01:11:45 +0000 (11:11 +1000)
(cherry picked from commit b3bd8a270b4dd9ced6b5f9ba9ddd097b69d917e6)

bin/nsupdate/nsupdate.c

index ce3798968dd78420e7f5b4ccff20df7838cb932f..82ad2a34fe7401e2421bb6c524fb220c74ac234c 100644 (file)
@@ -173,6 +173,7 @@ static unsigned int udp_timeout = 3;
 static unsigned int udp_retries = 3;
 static dns_rdataclass_t defaultclass = dns_rdataclass_in;
 static dns_rdataclass_t zoneclass = dns_rdataclass_none;
+static isc_mutex_t answer_lock;
 static dns_message_t *answer = NULL;
 static uint32_t default_ttl = 0;
 static bool default_ttl_set = false;
@@ -985,6 +986,8 @@ setup_system(void) {
        } else if (keyfile != NULL) {
                setup_keyfile(gmctx, glctx);
        }
+
+       isc_mutex_init(&answer_lock);
 }
 
 static int
@@ -2184,9 +2187,11 @@ do_next_command(char *cmdline) {
                return (STATUS_MORE);
        }
        if (strcasecmp(word, "answer") == 0) {
+               LOCK(&answer_lock);
                if (answer != NULL) {
                        show_message(stdout, answer, "Answer:");
                }
+               UNLOCK(&answer_lock);
                return (STATUS_MORE);
        }
        if (strcasecmp(word, "key") == 0) {
@@ -2414,6 +2419,7 @@ update_completed(isc_task_t *task, isc_event_t *event) {
                return;
        }
 
+       LOCK(&answer_lock);
        result = dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &answer);
        check_result(result, "dns_message_create");
        result = dns_request_getresponse(request, answer,
@@ -2467,6 +2473,7 @@ update_completed(isc_task_t *task, isc_event_t *event) {
        if (debugging) {
                show_message(stderr, answer, "\nReply from update query:");
        }
+       UNLOCK(&answer_lock);
 
 done:
        dns_request_destroy(&request);
@@ -3213,9 +3220,11 @@ start_update(void) {
 
        ddebug("start_update()");
 
+       LOCK(&answer_lock);
        if (answer != NULL) {
                dns_message_destroy(&answer);
        }
+       UNLOCK(&answer_lock);
 
        /*
         * If we have both the zone and the servers we have enough information
@@ -3294,9 +3303,11 @@ static void
 cleanup(void) {
        ddebug("cleanup()");
 
+       LOCK(&answer_lock);
        if (answer != NULL) {
                dns_message_destroy(&answer);
        }
+       UNLOCK(&answer_lock);
 
 #ifdef GSSAPI
        if (tsigkey != NULL) {
@@ -3347,6 +3358,8 @@ cleanup(void) {
                isc_mem_stats(gmctx, stderr);
        }
        isc_mem_destroy(&gmctx);
+
+       isc_mutex_destroy(&answer_lock);
 }
 
 static void