From de10b83a231451e03d08b3293c503d11ea03a90b Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 11 Mar 1999 00:26:21 +0000 Subject: [PATCH] * local label offset 255 is reserved. * don't add domainnames with local compression pointers as valid global compression targets unless edns is high enough. --- lib/dns/compress.c | 20 +++++++++++--------- lib/dns/include/dns/compress.h | 8 ++++++-- lib/dns/name.c | 6 +++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/dns/compress.c b/lib/dns/compress.c index d53d02632e..8a84e32721 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -15,7 +15,7 @@ * SOFTWARE. */ - /* $Id: compress.c,v 1.6 1999/03/06 04:08:29 halley Exp $ */ + /* $Id: compress.c,v 1.7 1999/03/11 00:26:20 marka Exp $ */ #include @@ -124,7 +124,7 @@ dns_compress_localinit(dns_compress_t *cctx, dns_name_t *owner, labels --; wl++; ll++; - if (ll > 255) + if (ll > 254) return (DNS_R_SUCCESS); dns_name_getlabel(&name, 0, &label); if (dns_label_type(&label) != dns_labeltype_bitstring) @@ -159,7 +159,7 @@ dns_compress_localinit(dns_compress_t *cctx, dns_name_t *owner, return (DNS_R_SUCCESS); } ll++; - if (ll > 255) + if (ll > 254) return (DNS_R_SUCCESS); } while (bits > 1); } @@ -242,19 +242,21 @@ dns_compress_findlocal(dns_compress_t *cctx, dns_name_t *name, void dns_compress_add(dns_compress_t *cctx, dns_name_t *prefix, - dns_name_t *suffix, isc_uint16_t offset) + dns_name_t *suffix, isc_uint16_t offset, + isc_boolean_t local) { - isc_uint16_t local; + isc_uint16_t localoffset; REQUIRE(VALID_CCTX(cctx)); if (cctx->local != NULL && (cctx->allowed & DNS_COMPRESS_LOCAL) != 0) { REQUIRE(cctx->rdata <= offset); - local = offset - cctx->rdata + 256; - compress_add(cctx->local, prefix, suffix, local, ISC_TRUE, + localoffset = offset - cctx->rdata + 256; + compress_add(cctx->local, prefix, suffix, localoffset, ISC_TRUE, cctx->mctx); } - compress_add(cctx->global, prefix, suffix, offset, cctx->global16, - cctx->mctx); + if ((cctx->edns > -1) || !local) + compress_add(cctx->global, prefix, suffix, offset, + cctx->global16, cctx->mctx); } void diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index 2142ce7bd6..9ca23b1cd5 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -208,10 +208,14 @@ dns_compress_findlocal(dns_compress_t *cctx, dns_name_t *name, void dns_compress_add(dns_compress_t *cctx, dns_name_t *prefix, - dns_name_t *suffix, isc_uint16_t offset); + dns_name_t *suffix, isc_uint16_t offset, + isc_boolean_t local); /* * Add compression pointers for labels in prefix to RBT's. - * If 'prefix' is absolute 'suffix' must be NULL. + * If 'prefix' is absolute 'suffix' must be NULL otherwise + * suffix must be absolute. + * 'local' indicates that the domain name at offset contains + * a local compression pointer. * * Requires: * 'cctx' initalised diff --git a/lib/dns/name.c b/lib/dns/name.c index 92ec4afce1..6dd281cda2 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -2057,7 +2057,7 @@ dns_name_towire(dns_name_t *name, dns_compress_t *cctx, isc_buffer_putuint16(target, go); } if (gp.length != 0) - dns_compress_add(cctx, &gp, &gs, offset); + dns_compress_add(cctx, &gp, &gs, offset, ISC_FALSE); } else if (lf) { if (target->length - target->used < lp.length) return (DNS_R_NOSPACE); @@ -2078,14 +2078,14 @@ dns_name_towire(dns_name_t *name, dns_compress_t *cctx, isc_buffer_putuint16(target, lo); } if (lp.length != 0) - dns_compress_add(cctx, &lp, &ls, offset); + dns_compress_add(cctx, &lp, &ls, offset, ISC_TRUE); } else { if (target->length - target->used < name->length) return (DNS_R_NOSPACE); (void)memcpy((unsigned char *)target->base + target->used, name->ndata, (size_t)name->length); isc_buffer_add(target, name->length); - dns_compress_add(cctx, name, NULL, offset); + dns_compress_add(cctx, name, NULL, offset, ISC_FALSE); } return (DNS_R_SUCCESS); }