From 942d1a339b1fe617f7d17d66cb5fccce798d15ae Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Tue, 14 Nov 2000 23:29:55 +0000 Subject: [PATCH] Decompression contexts now take a type instead of the "strict" boolean value - the type can be "any", "strict", or "none". This fixes potential problems with compression in unknown rr types. --- bin/named/client.c | 4 ++-- bin/tests/compress_test.c | 4 ++-- bin/tests/names/t_names.c | 4 ++-- bin/tests/rdata_test.c | 4 ++-- lib/dns/compress.c | 26 +++++++++++++++++--------- lib/dns/include/dns/compress.h | 33 +++++++++++++++++++-------------- lib/dns/journal.c | 4 ++-- lib/dns/message.c | 4 ++-- lib/dns/opt.c | 4 ++-- lib/dns/rdata.c | 4 ++-- 10 files changed, 52 insertions(+), 39 deletions(-) diff --git a/bin/named/client.c b/bin/named/client.c index 9028c68842..068417d90e 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: client.c,v 1.127 2000/11/13 21:33:54 bwelling Exp $ */ +/* $Id: client.c,v 1.128 2000/11/14 23:29:44 bwelling Exp $ */ #include @@ -1072,7 +1072,7 @@ client_getoptattrs(ns_client_t *client, dns_rdataset_t *opt) { switch (optattr.code) { case DNS_OPTCODE_ZONE: dns_decompress_init(&dctx, 0, - ISC_FALSE); + DNS_DECOMPRESS_NONE); client->opt_zone = isc_mem_get( client->mctx, sizeof(*client->opt_zone)); diff --git a/bin/tests/compress_test.c b/bin/tests/compress_test.c index 2494f8882d..4750f51b9f 100644 --- a/bin/tests/compress_test.c +++ b/bin/tests/compress_test.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: compress_test.c,v 1.21 2000/11/10 05:34:09 bwelling Exp $ */ +/* $Id: compress_test.c,v 1.22 2000/11/14 23:29:45 bwelling Exp $ */ #include @@ -177,7 +177,7 @@ test(unsigned int allowed, dns_name_t *name1, dns_name_t *name2, isc_buffer_setactive(&source, source.used); isc_buffer_init(&target, buf2, sizeof(buf2)); - dns_decompress_init(&dctx, -1, ISC_TRUE); + dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); dns_name_init(&name, NULL); RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE, diff --git a/bin/tests/names/t_names.c b/bin/tests/names/t_names.c index a876556c85..28f9eba331 100644 --- a/bin/tests/names/t_names.c +++ b/bin/tests/names/t_names.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: t_names.c,v 1.28 2000/08/01 01:14:06 tale Exp $ */ +/* $Id: t_names.c,v 1.29 2000/11/14 23:29:47 bwelling Exp $ */ #include @@ -2147,7 +2147,7 @@ test_dns_name_fromwire(char *datafile_name, int testname_offset, int downcase, isc_buffer_init(&iscbuf2, buf2, buflen); dns_name_init(&dns_name1, NULL); - dns_decompress_init(&dctx, -1, ISC_TRUE); + dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, dc_method); dns_result = dns_name_fromwire(&dns_name1, &iscbuf1, &dctx, downcase ? ISC_TRUE : ISC_FALSE, diff --git a/bin/tests/rdata_test.c b/bin/tests/rdata_test.c index fb631d0034..525ce3cd5d 100644 --- a/bin/tests/rdata_test.c +++ b/bin/tests/rdata_test.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdata_test.c,v 1.32 2000/11/09 23:54:55 bwelling Exp $ */ +/* $Id: rdata_test.c,v 1.33 2000/11/14 23:29:46 bwelling Exp $ */ #include @@ -1000,7 +1000,7 @@ main(int argc, char *argv[]) { isc_buffer_setactive(&wbuf, len); dns_rdata_init(&rdata); isc_buffer_init(&dbuf, inbuf, sizeof(inbuf)); - dns_decompress_init(&dctx, -1, ISC_FALSE); + dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_ANY); result = dns_rdata_fromwire(&rdata, class, type, &wbuf, &dctx, ISC_FALSE, &dbuf); dns_decompress_invalidate(&dctx); diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 76ebb094c4..4857014eb2 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: compress.c,v 1.35 2000/08/01 01:22:14 tale Exp $ */ +/* $Id: compress.c,v 1.36 2000/11/14 23:29:49 bwelling Exp $ */ #define DNS_NAME_USEINLINE 1 @@ -195,14 +195,15 @@ dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset) { ***/ void -dns_decompress_init(dns_decompress_t *dctx, int edns, isc_boolean_t strict) { +dns_decompress_init(dns_decompress_t *dctx, int edns, + dns_decompresstype_t type) { REQUIRE(dctx != NULL); REQUIRE(edns >= -1 && edns <= 255); dctx->allowed = DNS_COMPRESS_NONE; dctx->edns = edns; - dctx->strict = strict; + dctx->type = type; dctx->rdata = 0; dctx->magic = DCTX_MAGIC; } @@ -220,10 +221,17 @@ dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed) { REQUIRE(VALID_DCTX(dctx)); - if (dns_decompress_strict(dctx)) - dctx->allowed = allowed; - else + switch (dctx->type) { + case DNS_DECOMPRESS_ANY: dctx->allowed = DNS_COMPRESS_ALL; + break; + case DNS_DECOMPRESS_NONE: + dctx->allowed = DNS_COMPRESS_NONE; + break; + case DNS_DECOMPRESS_STRICT: + dctx->allowed = allowed; + break; + } } unsigned int @@ -242,12 +250,12 @@ dns_decompress_edns(dns_decompress_t *dctx) { return (dctx->edns); } -isc_boolean_t -dns_decompress_strict(dns_decompress_t *dctx) { +dns_decompresstype_t +dns_decompress_type(dns_decompress_t *dctx) { REQUIRE(VALID_DCTX(dctx)); - return (dctx->strict); + return (dctx->type); } /*** diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index a7c131e047..6a0d1cab0a 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: compress.h,v 1.18 2000/08/01 01:23:46 tale Exp $ */ +/* $Id: compress.h,v 1.19 2000/11/14 23:29:55 bwelling Exp $ */ #ifndef DNS_COMPRESS_H #define DNS_COMPRESS_H 1 @@ -40,9 +40,7 @@ ISC_LANG_BEGINDECLS #define DNS_COMPRESS_ALL 0x03 /* all compression. */ /* - * XXX An API for manipulating these structures will be forthcoming. - * Also magic numbers, _init() and _invalidate(), etc. At that time, - * direct manipulation of the structures will be strongly discouraged. + * Direct manipulation of the structures is strongly discouraged. */ struct dns_compress { @@ -55,12 +53,18 @@ struct dns_compress { isc_mem_t *mctx; /* Memeory context. */ }; +typedef enum { + DNS_DECOMPRESS_ANY, /* Any compression */ + DNS_DECOMPRESS_STRICT, /* Allowed compression */ + DNS_DECOMPRESS_NONE /* No compression */ +} dns_decompresstype_t; + struct dns_decompress { - unsigned int magic; /* Magic number. */ - unsigned int allowed; /* Allowed methods. */ - unsigned int rdata; /* Start of local rdata. */ - int edns; /* Edns version or -1. */ - isc_boolean_t strict; /* Strict checking */ + unsigned int magic; /* Magic number. */ + unsigned int allowed; /* Allowed methods. */ + unsigned int rdata; /* Start of local rdata. */ + int edns; /* Edns version or -1. */ + dns_decompresstype_t type; /* Strict checking */ }; isc_result_t @@ -176,11 +180,12 @@ dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset); */ void -dns_decompress_init(dns_decompress_t *dctx, int edns, isc_boolean_t strict); +dns_decompress_init(dns_decompress_t *dctx, int edns, + dns_decompresstype_t type); /* * Initalises 'dctx'. - * Records 'edns' and 'strict' into the structure. + * Records 'edns' and 'type' into the structure. * * Requires: * 'dctx' to be a valid pointer. @@ -226,11 +231,11 @@ dns_decompress_edns(dns_decompress_t *dctx); * 'dctx' to be initalised */ -isc_boolean_t -dns_decompress_strict(dns_decompress_t *dctx); +dns_decompresstype_t +dns_decompress_type(dns_decompress_t *dctx); /* - * Returns 'dctx->strict' + * Returns 'dctx->type' * * Requires: * 'dctx' to be initalised diff --git a/lib/dns/journal.c b/lib/dns/journal.c index 9921e74fd3..63ae5ecac4 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: journal.c,v 1.62 2000/10/31 03:21:52 marka Exp $ */ +/* $Id: journal.c,v 1.63 2000/11/14 23:29:50 bwelling Exp $ */ #include @@ -1176,7 +1176,7 @@ dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write, */ isc_buffer_init(&j->it.source, NULL, 0); isc_buffer_init(&j->it.target, NULL, 0); - dns_decompress_init(&j->it.dctx, -1, ISC_FALSE); + dns_decompress_init(&j->it.dctx, -1, DNS_DECOMPRESS_NONE); j->state = write ? JOURNAL_STATE_WRITE : JOURNAL_STATE_READ; diff --git a/lib/dns/message.c b/lib/dns/message.c index f442f4e164..9e0caeb8b7 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: message.c,v 1.157 2000/11/10 03:16:18 gson Exp $ */ +/* $Id: message.c,v 1.158 2000/11/14 23:29:51 bwelling Exp $ */ /*** *** Imports @@ -1493,7 +1493,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, /* * -1 means no EDNS. */ - dns_decompress_init(&dctx, -1, ISC_FALSE); + dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_ANY); dns_decompress_setmethods(&dctx, DNS_COMPRESS_GLOBAL14); diff --git a/lib/dns/opt.c b/lib/dns/opt.c index d003819c35..dc74f63aae 100644 --- a/lib/dns/opt.c +++ b/lib/dns/opt.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: opt.c,v 1.5 2000/11/13 21:33:59 bwelling Exp $ */ +/* $Id: opt.c,v 1.6 2000/11/14 23:29:52 bwelling Exp $ */ #include @@ -167,7 +167,7 @@ dns_opt_attrtotext(dns_optattr_t *attr, isc_buffer_t *target, case DNS_OPTCODE_ZONE: ADD_STRING(target, "; ZONE attribute: ", zonefail0); dns_fixedname_init(&fname); - dns_decompress_init(&dctx, 0, ISC_FALSE); + dns_decompress_init(&dctx, 0, DNS_DECOMPRESS_NONE); isc_buffer_init(&source, attr->value.base, attr->value.length); isc_buffer_add(&source, attr->value.length); isc_buffer_setactive(&source, attr->value.length); diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index e2f796e084..fc6b3ce20b 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rdata.c,v 1.122 2000/11/10 01:37:40 bwelling Exp $ */ +/* $Id: rdata.c,v 1.123 2000/11/14 23:29:53 bwelling Exp $ */ #include #include @@ -543,7 +543,7 @@ rdata_valid(isc_buffer_t *buf, dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_region_t r; isc_result_t result; - dns_decompress_init(&dctx, -1, ISC_TRUE); + dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); dns_rdata_init(&rdata); result = isc_buffer_allocate(mctx, &tbuf, isc_buffer_usedlength(buf)); if (result == ISC_R_SUCCESS) {