]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Address potential thread issues:
authorMark Andrews <marka@isc.org>
Wed, 24 Jun 2020 03:42:30 +0000 (13:42 +1000)
committerMark Andrews <marka@isc.org>
Thu, 25 Jun 2020 11:18:45 +0000 (21:18 +1000)
Assign and then check node for NULL to address another thread
changing radix->head in the meantime.

Move 'node != NULL' check into while loop test to silence cppcheck
false positive.

Fix pointer != NULL style.

(cherry picked from commit 51f08d20954f7eb5601dc7aca0cfa80d438db107)

lib/isc/radix.c

index 3781861ce2d382e714d1a5c29c5ddc656cd7233d..4e8a3127a1866d9734414ee7fb074cc912f66c04 100644 (file)
@@ -250,35 +250,38 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
 
        *target = NULL;
 
-       if (radix->head == NULL) {
+       node = radix->head;
+
+       if (node == NULL) {
                return (ISC_R_NOTFOUND);
        }
 
-       node = radix->head;
        addr = isc_prefix_touchar(prefix);
        bitlen = prefix->bitlen;
 
-       while (node->bit < bitlen) {
-               if (node->prefix)
+       while (node != NULL && node->bit < bitlen) {
+               if (node->prefix) {
                        stack[cnt++] = node;
+               }
 
                if (BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07)))
+               {
                        node = node->r;
-               else
+               } else {
                        node = node->l;
-
-               if (node == NULL)
-                       break;
+               }
        }
 
-       if (node && node->prefix)
+       if (node != NULL && node->prefix) {
                stack[cnt++] = node;
+       }
 
        while (cnt-- > 0) {
                node = stack[cnt];
 
-               if (prefix->bitlen < node->bit)
+               if (prefix->bitlen < node->bit) {
                        continue;
+               }
 
                if (_comp_with_mask(isc_prefix_tochar(node->prefix),
                                    isc_prefix_tochar(prefix),