]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
dns_name_totext() now allows names with 0 labels, which format as "@"
authorDavid Lawrence <source@isc.org>
Mon, 31 Jul 2000 23:09:49 +0000 (23:09 +0000)
committerDavid Lawrence <source@isc.org>
Mon, 31 Jul 2000 23:09:49 +0000 (23:09 +0000)
lib/dns/include/dns/name.h
lib/dns/name.c

index 5dffb563e7e9f3b37f589327dace7ce794f92415..9f1336842bf63ac17266a5968416c968ce21d2d0 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: name.h,v 1.76 2000/07/27 09:48:04 tale Exp $ */
+/* $Id: name.h,v 1.77 2000/07/31 23:09:47 tale Exp $ */
 
 #ifndef DNS_NAME_H
 #define DNS_NAME_H 1
@@ -873,8 +873,14 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
 /*
  * Convert 'name' into text format, storing the result in 'target'.
  *     
- * If 'omit_final_dot' is true, then the final '.' in absolute
- * names other than the root name will be omitted.
+ * Notes:
+ *     If 'omit_final_dot' is true, then the final '.' in absolute
+ *     names other than the root name will be omitted.
+ *
+ *     If dns_name_countlabels == 0, the name will be "@", representing the
+ *     current origin as described by RFC 1035.
+ *
+ *     The name is not NUL terminated.
  *
  * Requires:
  *
@@ -882,8 +888,6 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
  *
  *     'target' is a valid buffer.
  *
- *     dns_name_countlabels(name) > 0
- *
  *     if dns_name_isabsolute == FALSE, then omit_final_dot == FALSE
  *
  * Ensures:
index 0d038589fe94a9636c3d4cee06bca5624577cfef..49210c13efe1ff4026c22e7d5ee085e96b12edd2 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: name.c,v 1.98 2000/07/27 09:46:16 tale Exp $ */
+/* $Id: name.c,v 1.99 2000/07/31 23:09:49 tale Exp $ */
 
 #include <config.h>
 
@@ -1707,7 +1707,6 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
         * wire format.
         */
        REQUIRE(VALID_NAME(name));
-       REQUIRE(name->labels > 0);
 
        ndata = name->ndata;
        nlen = name->length;
@@ -1717,18 +1716,47 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
 
        trem = tlen;
 
-       /* Special handling for root label. */
-       if (nlen == 1 && labels == 1 && *ndata == 0) {
+       if (labels == 0 && nlen == 0) {
+               /*
+                * Special handling for an empty name.
+                */
+               if (trem == 0)
+                       return (ISC_R_NOSPACE);
+
+               /*
+                * The names of these booleans are misleading in this case.
+                * This empty name is not necessarily from the root node of
+                * the DNS root zone, nor is a final dot going to be included.
+                * They need to be set this way, though, to keep the "@"
+                * from being trounced.
+                */
                saw_root = ISC_TRUE;
-               labels = 0;
+               omit_final_dot = ISC_FALSE;
+               *tdata++ = '@';
+               trem--;
+
+               /*
+                * Skip the while() loop.
+                */
                nlen = 0;
+       } else if (nlen == 1 && labels == 1 && *ndata == '\0') {
+               /*
+                * Special handling for the root label.
+                */
                if (trem == 0)
                        return (ISC_R_NOSPACE);
+
+               saw_root = ISC_TRUE;
+               omit_final_dot = ISC_FALSE;
                *tdata++ = '.';
                trem--;
-               omit_final_dot = ISC_FALSE;
+
+               /*
+                * Skip the while() loop.
+                */
+               nlen = 0;
        }
-               
+
        while (labels > 0 && nlen > 0 && trem > 0) {
                labels--;
                count = *ndata++;
@@ -1825,7 +1853,7 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
                } else {
                        FATAL_ERROR(__FILE__, __LINE__,
                                    "Unexpected label type %02x", count);
-                       /* Does not return. */
+                       /* NOTREACHED */
                }
                                         
                /*
@@ -1842,7 +1870,7 @@ dns_name_totext(dns_name_t *name, isc_boolean_t omit_final_dot,
 
        if (nlen != 0 && trem == 0)
                return (ISC_R_NOSPACE);
-       INSIST(nlen == 0);
+
        if (!saw_root || omit_final_dot)
                trem++;
 
@@ -3103,4 +3131,3 @@ dns_name_format(dns_name_t *name, char *cp, unsigned int size) {
        } else
                snprintf(cp, size, "<unknown>");
 }
-