2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +00:00

make names empty when construction fails instead of invalidating them

This commit is contained in:
Bob Halley
1999-08-12 20:26:45 +00:00
parent a7de941669
commit 70fdfcd1fa
2 changed files with 23 additions and 26 deletions

View File

@@ -206,7 +206,7 @@ extern dns_name_t *dns_wildcardname;
void dns_name_init(dns_name_t *name, unsigned char *offsets); void dns_name_init(dns_name_t *name, unsigned char *offsets);
/* /*
* Make 'name' empty. * Initialize 'name'.
* *
* Notes: * Notes:
* 'offsets' is never required to be non-NULL, but specifying a * 'offsets' is never required to be non-NULL, but specifying a

View File

@@ -139,6 +139,18 @@ static unsigned char maptolower[] = {
set_offsets(name, var, ISC_FALSE, ISC_FALSE, ISC_FALSE); \ set_offsets(name, var, ISC_FALSE, ISC_FALSE, ISC_FALSE); \
} }
/*
* Note: If additional attributes are added that should not be set for
* empty names, MAKE_EMPTY() must be changed so it clears them.
*/
#define MAKE_EMPTY(name) \
do { \
name->ndata = NULL; \
name->length = 0; \
name->labels = 0; \
name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; \
} while (0);
static struct dns_name root = { static struct dns_name root = {
NAME_MAGIC, NAME_MAGIC,
(unsigned char *)"", 1, 1, (unsigned char *)"", 1, 1,
@@ -261,7 +273,7 @@ dns_label_getbit(dns_label_t *label, unsigned int n) {
void void
dns_name_init(dns_name_t *name, unsigned char *offsets) { dns_name_init(dns_name_t *name, unsigned char *offsets) {
/* /*
* Make 'name' empty. * Initialize 'name'.
*/ */
name->magic = NAME_MAGIC; name->magic = NAME_MAGIC;
@@ -1012,13 +1024,9 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
kind = ft_init; kind = ft_init;
/* /*
* Invalidate 'name'. * Make 'name' empty in case of failure.
*/ */
name->magic = 0; MAKE_EMPTY(name);
name->ndata = NULL;
name->length = 0;
name->labels = 0;
name->attributes = 0;
/* /*
* Set up the state machine. * Set up the state machine.
@@ -1528,7 +1536,6 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
} else } else
name->attributes |= DNS_NAMEATTR_ABSOLUTE; name->attributes |= DNS_NAMEATTR_ABSOLUTE;
name->magic = NAME_MAGIC;
name->ndata = (unsigned char *)target->base + target->used; name->ndata = (unsigned char *)target->base + target->used;
name->labels = labels; name->labels = labels;
name->length = nused; name->length = nused;
@@ -1941,13 +1948,9 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
INIT_OFFSETS(name, offsets, odata); INIT_OFFSETS(name, offsets, odata);
/* /*
* Invalidate 'name'. * Make 'name' empty in case of failure.
*/ */
name->magic = 0; MAKE_EMPTY(name);
name->ndata = NULL;
name->length = 0;
name->labels = 0;
name->attributes = 0;
/* /*
* Initialize things to make the compiler happy; they're not required. * Initialize things to make the compiler happy; they're not required.
@@ -2187,7 +2190,6 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
if (!done) if (!done)
return (DNS_R_UNEXPECTEDEND); return (DNS_R_UNEXPECTEDEND);
name->magic = NAME_MAGIC;
name->ndata = (unsigned char *)target->base + target->used; name->ndata = (unsigned char *)target->base + target->used;
name->labels = labels; name->labels = labels;
name->length = nused; name->length = nused;
@@ -2406,14 +2408,7 @@ dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name,
labels += suffix->labels; labels += suffix->labels;
} }
if (length > nrem) { if (length > nrem) {
/* MAKE_EMPTY(name);
* Invalidate 'name'.
*/
name->magic = 0;
name->ndata = NULL;
name->length = 0;
name->labels = 0;
name->attributes = 0;
return (DNS_R_NOSPACE); return (DNS_R_NOSPACE);
} }
@@ -2765,7 +2760,10 @@ dns_name_dup(dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) {
* Make 'target' a dynamically allocated copy of 'source'. * Make 'target' a dynamically allocated copy of 'source'.
*/ */
target->magic = 0; /* Invalidate 'target' in case of failure. */ /*
* Make 'target' empty in case of failure.
*/
MAKE_EMPTY(target);
target->ndata = isc_mem_get(mctx, source->length); target->ndata = isc_mem_get(mctx, source->length);
if (target->ndata == NULL) if (target->ndata == NULL)
@@ -2773,7 +2771,6 @@ dns_name_dup(dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) {
memcpy(target->ndata, source->ndata, source->length); memcpy(target->ndata, source->ndata, source->length);
target->magic = NAME_MAGIC;
target->length = source->length; target->length = source->length;
target->labels = source->labels; target->labels = source->labels;
target->attributes = DNS_NAMEATTR_DYNAMIC | DNS_NAMEATTR_READONLY; target->attributes = DNS_NAMEATTR_DYNAMIC | DNS_NAMEATTR_READONLY;