]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
pullup:
authorAndreas Gustafsson <source@isc.org>
Mon, 11 Dec 2000 21:02:04 +0000 (21:02 +0000)
committerAndreas Gustafsson <source@isc.org>
Mon, 11 Dec 2000 21:02:04 +0000 (21:02 +0000)
Bitstring labels *still* suck.  They didn't somehow magically get less
sucky in the past couple of months.  The nerve.

Anyway, dns_name_split now correctly compacts the preceding bitstring label
(if any) when a maximal bitstring is split.

It also correctly creates the suffix when a maximal bitstring is split.
It was doing this incorrectly before, independent of the compaction issue.

lib/dns/name.c

index 9c88601a127e7b59b37f2522821d3b7fc93bb15f..8d5050beb23383219fac704b0d2fdbd0d9e3f99e 100644 (file)
@@ -15,7 +15,7 @@
  * SOFTWARE.
  */
 
-/* $Id: name.c,v 1.93.2.1 2000/10/16 23:32:34 bwelling Exp $ */
+/* $Id: name.c,v 1.93.2.2 2000/12/11 21:02:04 gson Exp $ */
 
 #include <config.h>
 
@@ -2592,11 +2592,12 @@ dns_name_split(dns_name_t *name,
               dns_name_t *prefix, dns_name_t *suffix)
 
 {
-       dns_offsets_t name_odata, split_odata;
-       unsigned char *offsets, *splitoffsets;
+       dns_offsets_t name_odata, prefix_odata, suffix_odata;
+       unsigned char *offsets, *prefix_offsets = NULL, *suffix_offsets;
        isc_result_t result = ISC_R_SUCCESS;
        unsigned int splitlabel, bitbytes, mod, len;
        unsigned char *p, *src, *dst;
+       isc_boolean_t maybe_compact_prefix = ISC_FALSE;
 
        REQUIRE(VALID_NAME(name));
        REQUIRE((nbits == 0 &&
@@ -2665,11 +2666,14 @@ dns_name_split(dns_name_t *name,
                        }
 
                        /*
-                        * Set the new bit count.
+                        * Set the new bit count.  Also, when a bitstring
+                        * label being split is maximal length, compaction
+                        * might be necessary on the prefix.
                         */
-                       if (*p == 0)
+                       if (*p == 0) {
+                               maybe_compact_prefix = ISC_TRUE;
                                *p = 256 - nbits;
-                       else
+                       else
                                *p = *p - nbits;
 
                        /*
@@ -2743,8 +2747,8 @@ dns_name_split(dns_name_t *name,
                         */
                        INSIST(len = prefix->length);
 
-                       INIT_OFFSETS(prefix, splitoffsets, split_odata);
-                       set_offsets(prefix, splitoffsets, prefix);
+                       INIT_OFFSETS(prefix, prefix_offsets, prefix_odata);
+                       set_offsets(prefix, prefix_offsets, prefix);
 
                        INSIST(prefix->labels == splitlabel + 1 &&
                               prefix->length == len);
@@ -2768,7 +2772,9 @@ dns_name_split(dns_name_t *name,
                         * the new name.
                         */
                        src = &name->ndata[offsets[splitlabel] + 1];
-                       len = (*src++ - 1) / 8 - (bitbytes - 1);
+                       len = ((*src == 0 ? 256 : *src) - 1) / 8;
+                       len -= (bitbytes - 1);
+                       src++;
 
                        suffix->length = name->length -
                                offsets[splitlabel] - len;
@@ -2844,8 +2850,8 @@ dns_name_split(dns_name_t *name,
                         */
                        INSIST(len = suffix->length);
 
-                       INIT_OFFSETS(suffix, splitoffsets, split_odata);
-                       set_offsets(suffix, splitoffsets, suffix);
+                       INIT_OFFSETS(suffix, suffix_offsets, suffix_odata);
+                       set_offsets(suffix, suffix_offsets, suffix);
 
                        INSIST(suffix->labels == suffixlabels &&
                               suffix->length == len);
@@ -2856,6 +2862,16 @@ dns_name_split(dns_name_t *name,
 
        }
 
+       /*
+        * Compacting the prefix can't be done until after the suffix is
+        * set, because it would screw up the offsets table of 'name'
+        * when 'name' == 'prefix'.
+        */
+       if (maybe_compact_prefix && splitlabel > 0 &&
+           prefix->ndata[prefix_offsets[splitlabel - 1]] ==
+           DNS_LABELTYPE_BITSTRING)
+               compact(prefix, prefix_offsets);
+
        return (result);
 }