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

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.
This commit is contained in:
Brian Wellington
2000-11-14 23:29:55 +00:00
parent 3d9ce7519b
commit 942d1a339b
10 changed files with 52 additions and 39 deletions

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -1072,7 +1072,7 @@ client_getoptattrs(ns_client_t *client, dns_rdataset_t *opt) {
switch (optattr.code) { switch (optattr.code) {
case DNS_OPTCODE_ZONE: case DNS_OPTCODE_ZONE:
dns_decompress_init(&dctx, 0, dns_decompress_init(&dctx, 0,
ISC_FALSE); DNS_DECOMPRESS_NONE);
client->opt_zone = isc_mem_get( client->opt_zone = isc_mem_get(
client->mctx, client->mctx,
sizeof(*client->opt_zone)); sizeof(*client->opt_zone));

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -177,7 +177,7 @@ test(unsigned int allowed, dns_name_t *name1, dns_name_t *name2,
isc_buffer_setactive(&source, source.used); isc_buffer_setactive(&source, source.used);
isc_buffer_init(&target, buf2, sizeof(buf2)); 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); dns_name_init(&name, NULL);
RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE, RUNTIME_CHECK(dns_name_fromwire(&name, &source, &dctx, ISC_FALSE,

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -2147,7 +2147,7 @@ test_dns_name_fromwire(char *datafile_name, int testname_offset, int downcase,
isc_buffer_init(&iscbuf2, buf2, buflen); isc_buffer_init(&iscbuf2, buf2, buflen);
dns_name_init(&dns_name1, NULL); 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_decompress_setmethods(&dctx, dc_method);
dns_result = dns_name_fromwire(&dns_name1, &iscbuf1, dns_result = dns_name_fromwire(&dns_name1, &iscbuf1,
&dctx, downcase ? ISC_TRUE : ISC_FALSE, &dctx, downcase ? ISC_TRUE : ISC_FALSE,

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -1000,7 +1000,7 @@ main(int argc, char *argv[]) {
isc_buffer_setactive(&wbuf, len); isc_buffer_setactive(&wbuf, len);
dns_rdata_init(&rdata); dns_rdata_init(&rdata);
isc_buffer_init(&dbuf, inbuf, sizeof(inbuf)); 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, result = dns_rdata_fromwire(&rdata, class, type, &wbuf,
&dctx, ISC_FALSE, &dbuf); &dctx, ISC_FALSE, &dbuf);
dns_decompress_invalidate(&dctx); dns_decompress_invalidate(&dctx);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 #define DNS_NAME_USEINLINE 1
@@ -195,14 +195,15 @@ dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset) {
***/ ***/
void 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(dctx != NULL);
REQUIRE(edns >= -1 && edns <= 255); REQUIRE(edns >= -1 && edns <= 255);
dctx->allowed = DNS_COMPRESS_NONE; dctx->allowed = DNS_COMPRESS_NONE;
dctx->edns = edns; dctx->edns = edns;
dctx->strict = strict; dctx->type = type;
dctx->rdata = 0; dctx->rdata = 0;
dctx->magic = DCTX_MAGIC; dctx->magic = DCTX_MAGIC;
} }
@@ -220,10 +221,17 @@ dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed) {
REQUIRE(VALID_DCTX(dctx)); REQUIRE(VALID_DCTX(dctx));
if (dns_decompress_strict(dctx)) switch (dctx->type) {
dctx->allowed = allowed; case DNS_DECOMPRESS_ANY:
else
dctx->allowed = DNS_COMPRESS_ALL; 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 unsigned int
@@ -242,12 +250,12 @@ dns_decompress_edns(dns_decompress_t *dctx) {
return (dctx->edns); return (dctx->edns);
} }
isc_boolean_t dns_decompresstype_t
dns_decompress_strict(dns_decompress_t *dctx) { dns_decompress_type(dns_decompress_t *dctx) {
REQUIRE(VALID_DCTX(dctx)); REQUIRE(VALID_DCTX(dctx));
return (dctx->strict); return (dctx->type);
} }
/*** /***

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 #ifndef DNS_COMPRESS_H
#define DNS_COMPRESS_H 1 #define DNS_COMPRESS_H 1
@@ -40,9 +40,7 @@ ISC_LANG_BEGINDECLS
#define DNS_COMPRESS_ALL 0x03 /* all compression. */ #define DNS_COMPRESS_ALL 0x03 /* all compression. */
/* /*
* XXX An API for manipulating these structures will be forthcoming. * Direct manipulation of the structures is strongly discouraged.
* Also magic numbers, _init() and _invalidate(), etc. At that time,
* direct manipulation of the structures will be strongly discouraged.
*/ */
struct dns_compress { struct dns_compress {
@@ -55,12 +53,18 @@ struct dns_compress {
isc_mem_t *mctx; /* Memeory context. */ 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 { struct dns_decompress {
unsigned int magic; /* Magic number. */ unsigned int magic; /* Magic number. */
unsigned int allowed; /* Allowed methods. */ unsigned int allowed; /* Allowed methods. */
unsigned int rdata; /* Start of local rdata. */ unsigned int rdata; /* Start of local rdata. */
int edns; /* Edns version or -1. */ int edns; /* Edns version or -1. */
isc_boolean_t strict; /* Strict checking */ dns_decompresstype_t type; /* Strict checking */
}; };
isc_result_t isc_result_t
@@ -176,11 +180,12 @@ dns_compress_rollback(dns_compress_t *cctx, isc_uint16_t offset);
*/ */
void 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'. * Initalises 'dctx'.
* Records 'edns' and 'strict' into the structure. * Records 'edns' and 'type' into the structure.
* *
* Requires: * Requires:
* 'dctx' to be a valid pointer. * 'dctx' to be a valid pointer.
@@ -226,11 +231,11 @@ dns_decompress_edns(dns_decompress_t *dctx);
* 'dctx' to be initalised * 'dctx' to be initalised
*/ */
isc_boolean_t dns_decompresstype_t
dns_decompress_strict(dns_decompress_t *dctx); dns_decompress_type(dns_decompress_t *dctx);
/* /*
* Returns 'dctx->strict' * Returns 'dctx->type'
* *
* Requires: * Requires:
* 'dctx' to be initalised * 'dctx' to be initalised

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -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.source, NULL, 0);
isc_buffer_init(&j->it.target, 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 = j->state =
write ? JOURNAL_STATE_WRITE : JOURNAL_STATE_READ; write ? JOURNAL_STATE_WRITE : JOURNAL_STATE_READ;

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 *** Imports
@@ -1493,7 +1493,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source,
/* /*
* -1 means no EDNS. * -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); dns_decompress_setmethods(&dctx, DNS_COMPRESS_GLOBAL14);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
@@ -167,7 +167,7 @@ dns_opt_attrtotext(dns_optattr_t *attr, isc_buffer_t *target,
case DNS_OPTCODE_ZONE: case DNS_OPTCODE_ZONE:
ADD_STRING(target, "; ZONE attribute: ", zonefail0); ADD_STRING(target, "; ZONE attribute: ", zonefail0);
dns_fixedname_init(&fname); 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_init(&source, attr->value.base, attr->value.length);
isc_buffer_add(&source, attr->value.length); isc_buffer_add(&source, attr->value.length);
isc_buffer_setactive(&source, attr->value.length); isc_buffer_setactive(&source, attr->value.length);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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 <config.h> #include <config.h>
#include <ctype.h> #include <ctype.h>
@@ -543,7 +543,7 @@ rdata_valid(isc_buffer_t *buf, dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_region_t r; isc_region_t r;
isc_result_t result; isc_result_t result;
dns_decompress_init(&dctx, -1, ISC_TRUE); dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE);
dns_rdata_init(&rdata); dns_rdata_init(&rdata);
result = isc_buffer_allocate(mctx, &tbuf, isc_buffer_usedlength(buf)); result = isc_buffer_allocate(mctx, &tbuf, isc_buffer_usedlength(buf));
if (result == ISC_R_SUCCESS) { if (result == ISC_R_SUCCESS) {