diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 00f6f3e086..54a4cede40 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -15,7 +15,7 @@ * SOFTWARE. */ - /* $Id: compress.c,v 1.3 1999/02/24 06:31:31 marka Exp $ */ + /* $Id: compress.c,v 1.4 1999/02/26 00:25:12 marka Exp $ */ #include @@ -145,7 +145,8 @@ dns_compress_localinit(dns_compress_t *cctx, dns_name_t *owner, dns_name_fromregion(&prefix, ®ion); isc_buffer_init(&t, namebuf, sizeof namebuf, ISC_BUFFERTYPE_BINARY); - result = dns_name_cat(&prefix, &suffix, &name, &t); + result = dns_name_concatenate(&prefix, &suffix, &name, + &t); if (result != DNS_R_SUCCESS) return (DNS_R_SUCCESS); data = isc_mem_get(cctx->mctx, sizeof *data); @@ -386,7 +387,7 @@ compress_add(dns_rbt_t *root, dns_name_t *prefix, dns_name_t *suffix, dns_name_getlabelsequence(prefix, start, count, &name); isc_buffer_init(&target, buffer, sizeof buffer, ISC_BUFFERTYPE_BINARY); - result = dns_name_cat(&name, suffix, &full, &target); + result = dns_name_concatenate(&name, suffix, &full, &target); if (result != DNS_R_SUCCESS) return; data = isc_mem_get(mctx, sizeof *data); @@ -471,7 +472,7 @@ compress_find(dns_rbt_t *root, dns_name_t *name, dns_name_t *prefix, buf[1] = bits; dns_name_fromregion(&tmpprefix, ®ion); isc_buffer_clear(workspace); - result = dns_name_cat(&tmpprefix, &tmpsuffix, + result = dns_name_concatenate(&tmpprefix, &tmpsuffix, &tmpname, workspace); if (result != DNS_R_SUCCESS) continue; @@ -522,7 +523,8 @@ compress_find(dns_rbt_t *root, dns_name_t *name, dns_name_t *prefix, dns_name_init(&tmpprefix, NULL); else dns_name_getlabelsequence(name, 0, start - 1, &tmpprefix); - result = dns_name_cat(&tmpprefix, &tmpsuffix, prefix, workspace); + result = dns_name_concatenate(&tmpprefix, &tmpsuffix, prefix, + workspace); if (result != DNS_R_SUCCESS) return (ISC_FALSE); *offset = *data; diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index 9064a2fd08..7f4a1c7f68 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -208,10 +208,12 @@ dns_compress_add(dns_compress_t *cctx, dns_name_t *prefix, dns_name_t *suffix, isc_uint16_t offset); /* * Add compression pointers for labels in prefix to RBT's. + * If 'prefix' is absolute 'suffix' must be NULL. * * Requires: * 'cctx' initalised * 'prefix' to be initalised + * 'suffix' to be initalised or NULL */ void diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index 38c182d665..fe2b644606 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -663,11 +663,11 @@ dns_result_t dns_name_totext(dns_name_t *name, * DNS_R_NOSPACE */ -dns_result_t dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, - dns_name_t *name, isc_buffer_t *target); +dns_result_t dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, + dns_name_t *name, isc_buffer_t *target); /* * Concatenate 'prefix' & 'suffix' and return the result in 'name'. - * If either 'prefix' or 'suffix' is absolute the result is absolute. + * If 'prefix' is absolute 'suffix' must be NULL. * * Requires: * 'prefix' to be initalised diff --git a/lib/dns/name.c b/lib/dns/name.c index 6c97f73cf1..a1048da4a3 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -2049,8 +2049,8 @@ dns_name_towire(dns_name_t *name, dns_compress_t *cctx, } dns_result_t -dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, - isc_buffer_t *target) +dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, + isc_buffer_t *target) { unsigned char *ndata; unsigned char *offsets; @@ -2059,27 +2059,31 @@ dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, unsigned int labels; unsigned int count; isc_boolean_t absolute = ISC_FALSE; + dns_name_t tmp_name; - REQUIRE(VALID_NAME(name)); REQUIRE(VALID_NAME(prefix)); + if (prefix->labels != 0 && + (prefix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + REQUIRE(suffix == NULL); if (suffix != NULL) REQUIRE(VALID_NAME(suffix)); + if (name != NULL) + REQUIRE(VALID_NAME(name)); REQUIRE(isc_buffer_type(target) == ISC_BUFFERTYPE_BINARY); REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0); + if (name == NULL) { + name = &tmp_name; + dns_name_init(name, NULL); + } + nrem = target->length - target->used; ndata = (unsigned char *)target->base + target->used; if (nrem > 255) nrem = 255; - if (prefix->labels != 0 && - (prefix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { - count = prefix->length - 1; - labels = prefix->labels - 1; - absolute = ISC_TRUE; - } else { - count = prefix->length; - labels = prefix->labels; - } + + count = prefix->length; + labels = prefix->labels; if (count > nrem) return (DNS_R_NOSPACE); memcpy(ndata, prefix->ndata, count); @@ -2088,42 +2092,24 @@ dns_name_cat(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, /* append suffix */ if (suffix != NULL) { - if (suffix->labels != 0 && - (suffix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { - count = suffix->length - 1; - labels += suffix->labels - 1; - absolute = ISC_TRUE; - } else { - count = suffix->length; - labels += suffix->labels; - } + count = suffix->length; + labels += suffix->labels; if (count > nrem) return (DNS_R_NOSPACE); memcpy(ndata, suffix->ndata, count); ndata += count; } - if (absolute) { - /* root label */ - if (nrem < 1) - return (DNS_R_NOSPACE); - *ndata++ = 0; - labels++; - } - name->ndata = (unsigned char *)target->base + target->used; name->labels = labels; name->length = ndata - name->ndata; - if (absolute) - name->attributes |= DNS_NAMEATTR_ABSOLUTE; - else - name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; INIT_OFFSETS(name, offsets, odata); - if (name->length > 0) - set_offsets(name, offsets, ISC_FALSE, ISC_FALSE, ISC_FALSE); - - compact(name, offsets); + if (name->length > 0) { + set_offsets(name, offsets, ISC_FALSE, ISC_FALSE, ISC_TRUE); + compact(name, offsets); + } else + name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; isc_buffer_add(target, name->length); return (DNS_R_SUCCESS);