From 969cb06e15beb3639941b5e432b670fd53a55d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 26 Mar 2020 08:23:52 +0100 Subject: [PATCH 1/4] Fix missing include --- lib/isc/tests/timer_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/isc/tests/timer_test.c b/lib/isc/tests/timer_test.c index 92f5b82489..128ce76b93 100644 --- a/lib/isc/tests/timer_test.c +++ b/lib/isc/tests/timer_test.c @@ -13,6 +13,7 @@ #if HAVE_CMOCKA +#include #include #include #include From e3acfedbe3dcf3c2214d7c1fb5e2f3bc60a9957e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 25 Mar 2020 17:00:07 +0100 Subject: [PATCH 2/4] Fix 'Dead nested assignment's from scan-build-10 The 1 warning reported is: os.c:872:7: warning: Although the value stored to 'ptr' is used in the enclosing expression, the value is never actually read from 'ptr' if ((ptr = strtok_r(command, " \t", &last)) == NULL) { ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. --- bin/named/unix/os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index b1ac3b7773..c3b0bbee13 100644 --- a/bin/named/unix/os.c +++ b/bin/named/unix/os.c @@ -842,7 +842,7 @@ named_os_shutdownmsg(char *command, isc_buffer_t *text) { /* Skip the command name. */ - if ((ptr = strtok_r(command, " \t", &last)) == NULL) { + if (strtok_r(command, " \t", &last) == NULL) { return; } From f3ba17fedca645fc8d8ca322f794fca72225c63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 25 Mar 2020 17:25:45 +0100 Subject: [PATCH 3/4] Fix 'Dereference of null pointer' from scan-build-10 These are mostly false positives, the clang-analyzer FAQ[1] specifies why and how to fix it: > The reason the analyzer often thinks that a pointer can be null is > because the preceding code checked compared it against null. So if you > are absolutely sure that it cannot be null, remove the preceding check > and, preferably, add an assertion as well. The 2 warnings reported are: dnssec-cds.c:781:4: warning: Access to field 'base' results in a dereference of a null pointer (loaded from variable 'buf') isc_buffer_availableregion(buf, &r); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /builds/isc-projects/bind9/lib/isc/include/isc/buffer.h:996:36: note: expanded from macro 'isc_buffer_availableregion' ^ /builds/isc-projects/bind9/lib/isc/include/isc/buffer.h:821:16: note: expanded from macro 'ISC__BUFFER_AVAILABLEREGION' (_r)->base = isc_buffer_used(_b); \ ^~~~~~~~~~~~~~~~~~~ /builds/isc-projects/bind9/lib/isc/include/isc/buffer.h:152:29: note: expanded from macro 'isc_buffer_used' ((void *)((unsigned char *)(b)->base + (b)->used)) /*d*/ ^~~~~~~~~ 1 warning generated. -- ./main.c:1254:9: warning: Access to field 'sctx' results in a dereference of a null pointer (loaded from variable 'named_g_server') sctx = named_g_server->sctx; ^~~~~~~~~~~~~~~~~~~~ 1 warning generated. References: 1. https://clang-analyzer.llvm.org/faq.html#null_pointer --- bin/dnssec/dnssec-cds.c | 4 ++++ bin/named/main.c | 1 + 2 files changed, 5 insertions(+) diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index 59aa45ee5f..0ef524a7e9 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -788,6 +788,8 @@ ds_from_cds(dns_rdatalist_t *dslist, isc_buffer_t *buf, dns_rdata_t *cds) { dns_rdata_ds_t ds; dns_rdata_t *rdata; + REQUIRE(buf != NULL); + rdata = rdata_get(); result = dns_rdata_tostruct(cds, &ds, NULL); @@ -807,6 +809,8 @@ ds_from_cdnskey(dns_rdatalist_t *dslist, isc_buffer_t *buf, isc_result_t result; unsigned i, n; + REQUIRE(buf != NULL); + n = sizeof(dtype)/sizeof(dtype[0]); for (i = 0; i < n; i++) { if (dtype[i] != 0) { diff --git a/bin/named/main.c b/bin/named/main.c index e4e4d81261..afdb25cae8 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -1229,6 +1229,7 @@ setup(void) { #endif named_server_create(named_g_mctx, &named_g_server); + ENSURE(named_g_server != NULL); sctx = named_g_server->sctx; /* From 2637a2ce9d1472ab3b7463410158f918f0a0ccb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 26 Mar 2020 09:56:41 +0100 Subject: [PATCH 4/4] Import parse_tsan.py file to v9_11 branch --- util/copyrights | 1 + util/parse_tsan.py | 112 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100755 util/parse_tsan.py diff --git a/util/copyrights b/util/copyrights index b762dbe39a..56c8b2f527 100644 --- a/util/copyrights +++ b/util/copyrights @@ -2642,6 +2642,7 @@ ./util/nanny.pl PERL 2000,2001,2004,2007,2012,2016,2018,2019,2020 ./util/new-func PERL 2005,2007,2012,2016,2018,2019,2020 ./util/nt-kit SH 1999,2000,2001,2004,2007,2012,2016,2018,2019,2020 +./util/parse_tsan.py PYTHON-BIN 2020 ./util/spacewhack.pl PERL 2000,2001,2004,2007,2012,2016,2018,2019,2020 ./util/tabify-changes SH 2004,2007,2012,2016,2018,2019,2020 ./util/update-drafts.pl PERL 2000,2001,2004,2007,2012,2016,2018,2019,2020 diff --git a/util/parse_tsan.py b/util/parse_tsan.py new file mode 100755 index 0000000000..6e4e478995 --- /dev/null +++ b/util/parse_tsan.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +############################################################################ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. +############################################################################ + +import sys, os, os.path, re +from hashlib import sha256 + +class State: + inside = False + block = "" + last_line = None + + mutexes = {} + m_index = 1 + threads = {} + t_index = 1 + pointers = {} + p_index = 1 + + def init(self): + self.reset() + + def reset(self): + self.inside = False + self.block = "" + + self.mutexes = {} + self.threads = {} + self.pointers = {} + self.pointers["0x000000000000"] = 0 + + self.m_index = 1 + self.t_index = 1 + self.p_index = 1 + +top = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + +out = os.path.join(top, "tsan") + +if not os.path.isdir(out): + os.mkdir(out) + +# Regular Expressions +mutex = re.compile(r"M\d+") +thread = re.compile(r"T\d+") +stack = re.compile(r"\s\(\S+\+0x\S+\)") +pointer = re.compile(r"0x[0-9a-f]+") +pid = re.compile(r"\(pid=\d+,?\)") +tid = re.compile(r"tid=\d+,?\s*") +worker = re.compile(r"\s+'(isc-worker|isc-net-)\d+'") +path = re.compile(top + "/") + +s = State() + + +with open(sys.argv[1], "r", encoding='utf-8') as f: + lines = f.readlines() + for line in lines: + if line == "==================\n": + if not s.inside: + s.inside = True + else: + dname = os.path.join(out, sha256(s.last_line.encode('utf-8')).hexdigest()) + if not os.path.isdir(dname): + os.mkdir(dname) + fname = os.path.join(dname, sha256(s.block.encode('utf-8')).hexdigest() + ".tsan") + if not os.path.isfile(fname): + with open(fname, "w", encoding='utf-8') as w: + w.write(s.block) + s.reset() + else: + for m in mutex.finditer(line): + k = m.group() + if k not in s.mutexes: + s.mutexes[k] = s.m_index + s.m_index += 1 + for m in thread.finditer(line): + k = m.group() + if k not in s.threads: + s.threads[k] = s.t_index + s.t_index += 1 + for m in pointer.finditer(line): + k = m.group() + if k not in s.pointers: + s.pointers[k] = s.p_index + s.p_index += 1 + for k, v in s.mutexes.items(): + r = re.compile(k) + line = r.sub("M%s" % v, line) + for k, v in s.threads.items(): + r = re.compile(k) + line = r.sub("T%s" % v, line) + for k, v in s.pointers.items(): + r = re.compile(k) + line = r.sub("0x%s" % str(v).zfill(12), line) + + line = stack.sub("", line) + line = pid.sub("", line) + line = tid.sub("", line) + line = worker.sub("", line) + line = path.sub("", line) + + s.block += line + s.last_line = line