mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-26 00:30:05 -04:00
dns_name_totext() now allows names with 0 labels, which format as "@"
This commit is contained in:
parent
9658892dbc
commit
051d1879fe
2 changed files with 48 additions and 17 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
saw_root = ISC_TRUE;
|
||||
labels = 0;
|
||||
nlen = 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;
|
||||
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>");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue