Commit 3d5cad69 authored by Mark Andrews's avatar Mark Andrews
Browse files

Adjusted error codes.

	txt_fromwire() was not coping with a zero length active buffer.
parent 47db0e1d
......@@ -54,11 +54,21 @@ main(int argc, char *argv[]) {
int wire = 0;
dns_compress_t cctx;
dns_decompress_t dctx;
int trunc = 0;
int add = 0;
int len;
int zero = 0;
int debug = 0;
while ((c = getopt(argc, argv, "qsw")) != -1) {
while ((c = getopt(argc, argv, "dqswtaz")) != -1) {
switch (c) {
case 'd':
debug = 1;
quiet = 0;
break;
case 'q':
quiet = 1;
debug = 0;
break;
case 's':
stats = 1;
......@@ -66,6 +76,15 @@ main(int argc, char *argv[]) {
case 'w':
wire = 1;
break;
case 't':
trunc = 1;
break;
case 'a':
add = 1;
break;
case 'z':
zero = 1;
break;
}
}
......@@ -81,15 +100,14 @@ main(int argc, char *argv[]) {
specials[')'] = 1;
specials['"'] = 1;
isc_lex_setspecials(lex, specials);
options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
ISC_LEXOPT_INITIALWS | ISC_LEXOPT_QSTRING;
options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);
RUNTIME_CHECK(isc_lex_openstream(lex, stdin) == ISC_R_SUCCESS);
while ((result = isc_lex_gettoken(lex, options | ISC_LEXOPT_NUMBER,
&token)) == ISC_R_SUCCESS) {
/* fprintf(stdout, "token.type = %d\n", token.type); */
if (debug) fprintf(stdout, "token.type = %d\n", token.type);
if (token.type == isc_tokentype_special) {
if (token.value.as_char == '(') {
parens++;
......@@ -130,10 +148,9 @@ main(int argc, char *argv[]) {
NULL, ISC_FALSE, &dbuf);
if (result != DNS_R_SUCCESS) {
fprintf(stdout,
"dns_rdata_fromtext != DNS_R_SUCCESS\n");
"dns_rdata_fromtext returned %s(%d)\n",
dns_result_totext(result), result);
fflush(stdout);
need_eol = 1;
continue;
}
......@@ -141,20 +158,32 @@ main(int argc, char *argv[]) {
if (wire) {
isc_buffer_init(&wbuf, wirebuf, sizeof(wirebuf),
ISC_BUFFERTYPE_BINARY);
if (dns_rdata_towire(&rdata, &cctx, &wbuf)
!= DNS_R_SUCCESS) {
result = dns_rdata_towire(&rdata, &cctx, &wbuf);
if (result != DNS_R_SUCCESS) {
fprintf(stdout,
"dns_rdata_towire != DNS_R_SUCCESS\n");
fflush(stdout);
"dns_rdata_towire returned %s(%d)\n",
dns_result_totext(result), result);
continue;
}
len = wbuf.used - dbuf.current;
if (zero)
len = 0;
if (trunc)
len = (len * 3) / 4;
if (add) {
isc_buffer_add(&wbuf, len / 4 + 1);
len += len / 4 + 1;
}
isc_buffer_setactive(&wbuf, len);
dns_rdata_init(&rdata);
isc_buffer_init(&dbuf, inbuf, sizeof(inbuf),
ISC_BUFFERTYPE_BINARY);
if (dns_rdata_fromwire(&rdata, 1, type, &wbuf, &dctx,
ISC_FALSE, &dbuf) != DNS_R_SUCCESS) {
result = dns_rdata_fromwire(&rdata, 1, type, &wbuf,
&dctx, ISC_FALSE, &dbuf);
if (result != DNS_R_SUCCESS) {
fprintf(stdout,
"dns_rdata_fromwire != DNS_R_SUCCESS\n");
"dns_rdata_fromwire returned %s(%d)\n",
dns_result_totext(result), result);
fflush(stdout);
continue;
}
......@@ -162,8 +191,10 @@ main(int argc, char *argv[]) {
isc_buffer_init(&tbuf, outbuf, sizeof(outbuf),
ISC_BUFFERTYPE_TEXT);
if (dns_rdata_totext(&rdata, &tbuf) != DNS_R_SUCCESS)
fprintf(stdout, "dns_rdata_totext != DNS_R_SUCCESS\n");
result = dns_rdata_totext(&rdata, &tbuf);
if (result != DNS_R_SUCCESS)
fprintf(stdout, "dns_rdata_totext returned %s(%d)\n",
dns_result_totext(result), result);
else
fprintf(stdout, "\"%.*s\"\n",
(int)tbuf.used, (char*)tbuf.base);
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gen.c,v 1.6 1999/01/19 05:38:31 marka Exp $ */
/* $Id: gen.c,v 1.7 1999/01/20 05:20:18 marka Exp $ */
#include <sys/types.h>
......@@ -32,43 +32,43 @@
#define FROMTEXTARGS "class, type, lexer, origin, downcase, target"
#define FROMTEXTCLASS "class"
#define FROMTEXTTYPE "type"
#define FROMTEXTDEF "DNS_R_DEFAULT"
#define FROMTEXTDEF "use_default = ISC_TRUE"
#define TOTEXTDECL "dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target"
#define TOTEXTARGS "rdata, origin, target"
#define TOTEXTCLASS "rdata->class"
#define TOTEXTTYPE "rdata->type"
#define TOTEXTDEF "DNS_R_DEFAULT"
#define TOTEXTDEF "use_default = ISC_TRUE"
#define FROMWIREDECL "dns_rdataclass_t class, dns_rdatatype_t type, isc_buffer_t *source, dns_decompress_t *dctx, isc_boolean_t downcase, isc_buffer_t *target"
#define FROMWIREARGS "class, type, source, dctx, downcase, target"
#define FROMWIRECLASS "class"
#define FROMWIRETYPE "type"
#define FROMWIREDEF "DNS_R_DEFAULT"
#define FROMWIREDEF "use_default = ISC_TRUE"
#define TOWIREDECL "dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target"
#define TOWIREARGS "rdata, cctx, target"
#define TOWIRECLASS "rdata->class"
#define TOWIRETYPE "rdata->type"
#define TOWIREDEF "DNS_R_DEFAULT"
#define TOWIREDEF "use_default = ISC_TRUE"
#define FROMSTRUCTDECL "dns_rdataclass_t class, dns_rdatatype_t type, void *source, isc_buffer_t *target"
#define FROMSTRUCTARGS "class, type, source, target"
#define FROMSTRUCTCLASS "class"
#define FROMSTRUCTTYPE "type"
#define FROMSTRUCTDEF "DNS_R_DEFAULT"
#define FROMSTRUCTDEF "use_default = ISC_TRUE"
#define TOSTRUCTDECL "dns_rdata_t *rdata, void *target"
#define TOSTRUCTARGS "rdata, target"
#define TOSTRUCTCLASS "rdata->class"
#define TOSTRUCTTYPE "rdata->type"
#define TOSTRUCTDEF "DNS_R_DEFAULT"
#define TOSTRUCTDEF "use_default = ISC_TRUE"
#define COMPAREDECL "dns_rdata_t *rdata1, dns_rdata_t *rdata2"
#define COMPAREARGS "rdata1, rdata2"
#define COMPARECLASS "rdata1->class"
#define COMPARETYPE "rdata1->type"
#define COMPAREDEF "-2"
#define COMPAREDEF "use_default = ISC_TRUE"
char copyright[] =
"/*\n\
......@@ -141,8 +141,7 @@ doswitch(char *name, char *function, char *args,
first = 0;
}
if (tt->type != lasttype && subswitch) {
fprintf(stdout, "\t\tdefault: result = %s; break; \\\n",
res);
fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
fputs(/*{*/ "\t\t} \\\n", stdout);
fputs("\t\tbreak; \\\n", stdout);
subswitch = 0;
......@@ -165,14 +164,14 @@ doswitch(char *name, char *function, char *args,
lasttype = tt->type;
}
if (subswitch) {
fprintf(stdout, "\t\tdefault: result = %s; break; \\\n", res);
fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
fputs(/*{*/ "\t\t}\n", stdout);
fputs("\t\tbreak; \\\n", stdout);
}
if (first)
fprintf(stdout, "\n#define %s result = %s;\n", name, res);
fprintf(stdout, "\n#define %s %s;\n", name, res);
else {
fprintf(stdout, "\tdefault: result = %s; break; \\\n", res);
fprintf(stdout, "\tdefault: %s; break; \\\n", res);
fputs(/*{*/ "\t}\n", stdout);
}
}
......@@ -215,23 +214,23 @@ add(int class, char *classname, int type, char *typename, char *dirname) {
tt = types;
oldtt = NULL;
while (tt && (tt->type < type)) {
while ((tt != NULL) && (tt->type < type)) {
oldtt = tt;
tt = tt->next;
}
while (tt && (tt->type == type) && (tt->class < class)) {
while ((tt != NULL) && (tt->type == type) && (tt->class < class)) {
if (strcmp(tt->typename, typename) != 0)
exit(1);
oldtt = tt;
tt = tt->next;
}
if (tt && (tt->type == type) && (tt->class == class))
if ((tt != NULL) && (tt->type == type) && (tt->class == class))
exit(1);
newtt->next = tt;
if (oldtt)
if (oldtt != NULL)
oldtt->next = newtt;
else
types = newtt;
......@@ -246,18 +245,18 @@ add(int class, char *classname, int type, char *typename, char *dirname) {
cc = classes;
oldcc = NULL;
while (cc && (cc->type < type)) {
while ((cc != NULL) && (cc->type < type)) {
oldcc = cc;
cc = cc->next;
}
if (cc && cc->type == type) {
if ((cc != NULL) && cc->type == type) {
free((char *)newcc);
return;
}
newcc->next = cc;
if (oldcc)
if (oldcc != NULL)
oldcc->next = newcc;
else
classes = newcc;
......
......@@ -37,10 +37,11 @@ typedef unsigned int dns_result_t;
#define DNS_R_TOOMANYHOPS 14
#define DNS_R_DISALLOWED 15
#define DNS_R_NOMORE 16
#define DNS_R_WIRE 17
#define DNS_R_DEFAULT 18
#define DNS_R_EXTRATOKEN 17
#define DNS_R_EXTRADATA 18
#define DNS_R_TEXTTOLONG 19
#define DNS_R_LASTENTRY 18 /* Last entry on list. */
#define DNS_R_LASTENTRY 19 /* Last entry on list. */
#define DNS_R_UNEXPECTED 0xFFFFFFFFL
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.4 1999/01/20 02:41:10 halley Exp $ */
/* $Id: rdata.c,v 1.5 1999/01/20 05:20:18 marka Exp $ */
#include <isc/buffer.h>
#include <isc/lex.h>
......@@ -71,8 +71,9 @@ dns_rdata_init(dns_rdata_t *rdata) {
int
dns_rdata_compare(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
int result;
int result = 0;
int l;
isc_boolean_t use_default = ISC_FALSE;
REQUIRE(rdata1 != NULL);
REQUIRE(rdata2 != NULL);
......@@ -87,7 +88,7 @@ dns_rdata_compare(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
COMPARESWITCH
if (result == -2) {
if (use_default) {
l = (rdata1->length > rdata2->length) ?
rdata1->length : rdata2->length;
if ((result = memcmp(rdata1->data, rdata2->data, l)) == 0)
......@@ -127,10 +128,11 @@ dns_rdata_fromwire(dns_rdata_t *rdata,
dns_decompress_t *dctx,
isc_boolean_t downcase,
isc_buffer_t *target) {
dns_result_t result;
dns_result_t result = DNS_R_NOTIMPLEMENTED;
isc_region_t region;
isc_buffer_t ss;
isc_buffer_t st;
isc_boolean_t use_default = ISC_FALSE;
ss = *source;
st = *target;
......@@ -138,12 +140,12 @@ dns_rdata_fromwire(dns_rdata_t *rdata,
FROMWIRESWITCH
if (result == DNS_R_DEFAULT)
result = DNS_R_NOTIMPLEMENTED;
if (use_default)
(void)NULL;
/* We should have consumed all out buffer */
if (!buffer_empty(source))
result = DNS_R_WIRE;
if (result == DNS_R_SUCCESS && !buffer_empty(source))
result = DNS_R_EXTRADATA;
if (rdata && result == DNS_R_SUCCESS) {
region.length = target->used - st.used;
......@@ -160,11 +162,12 @@ dns_rdata_fromwire(dns_rdata_t *rdata,
dns_result_t
dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx,
isc_buffer_t *target) {
dns_result_t result;
dns_result_t result = DNS_R_NOTIMPLEMENTED;
isc_boolean_t use_default = ISC_FALSE;
TOWIRESWITCH
if (result == DNS_R_DEFAULT) {
if (use_default) {
if (target->length < rdata->length)
return (DNS_R_NOSPACE);
memcpy(target->base, rdata->data, rdata->length);
......@@ -180,17 +183,39 @@ dns_rdata_fromtext(dns_rdata_t *rdata,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase,
isc_buffer_t *target) {
dns_result_t result;
dns_result_t result = DNS_R_NOTIMPLEMENTED;
isc_region_t region;
isc_buffer_t st;
isc_boolean_t use_default = ISC_FALSE;
isc_token_t token;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
st = *target;
region.base = target->base + target->used;
FROMTEXTSWITCH
if (result == DNS_R_DEFAULT)
result = DNS_R_NOTIMPLEMENTED;
if (use_default)
(void)NULL;
/*
* Consume to end of line / file.
* If not at end of line initially set error code.
*/
do {
if (isc_lex_gettoken(lexer, options, &token)
!= ISC_R_SUCCESS) {
if (result == DNS_R_SUCCESS)
result = DNS_R_UNEXPECTED;
break;
} else if (token.type != isc_tokentype_eol &&
token.type != isc_tokentype_eof) {
fprintf(stderr, "token_type = %d\n", token.type);
if (result == DNS_R_SUCCESS)
result = DNS_R_EXTRATOKEN;
} else
break;
} while (1);
if (rdata != NULL && result == DNS_R_SUCCESS) {
region.length = target->used - st.used;
......@@ -204,13 +229,15 @@ dns_rdata_fromtext(dns_rdata_t *rdata,
dns_result_t
dns_rdata_totext(dns_rdata_t *rdata, isc_buffer_t *target) {
dns_result_t result;
dns_result_t result = DNS_R_NOTIMPLEMENTED;
dns_name_t *origin = NULL;
isc_boolean_t use_default = ISC_FALSE;
TOTEXTSWITCH
if (result == DNS_R_DEFAULT)
result = DNS_R_NOTIMPLEMENTED;
if (use_default)
(void)NULL;
return (result);
}
......@@ -219,17 +246,18 @@ dns_rdata_fromstruct(dns_rdata_t *rdata,
dns_rdataclass_t class, dns_rdatatype_t type,
void *source,
isc_buffer_t *target) {
dns_result_t result;
dns_result_t result = DNS_R_NOTIMPLEMENTED;
isc_buffer_t st;
isc_region_t region;
isc_boolean_t use_default = ISC_FALSE;
region.base = target->base + target->used;
st = *target;
FROMSTRUCTSWITCH
if (result == DNS_R_DEFAULT)
result = DNS_R_NOTIMPLEMENTED;
if (use_default)
(void)NULL;
if (rdata != NULL && result == DNS_R_SUCCESS) {
region.length = target->used - st.used;
......@@ -242,12 +270,14 @@ dns_rdata_fromstruct(dns_rdata_t *rdata,
dns_result_t
dns_rdata_tostruct(dns_rdata_t *rdata, void *target) {
dns_result_t result;
dns_result_t result = DNS_R_NOTIMPLEMENTED;
isc_boolean_t use_default = ISC_FALSE;
TOSTRUCTSWITCH
if (result == DNS_R_DEFAULT)
result = DNS_R_NOTIMPLEMENTED;
if (use_default)
(void)NULL;
return (result);
}
......@@ -314,7 +344,7 @@ txt_fromtext(isc_textregion_t *source, isc_buffer_t *target) {
if (tregion.length < source->length + 1)
return (DNS_R_NOSPACE);
if (source->length > 255)
return (DNS_R_UNKNOWN);
return (DNS_R_TEXTTOLONG);
*tregion.base = source->length;
memcpy(tregion.base + 1, source->base, source->length);
isc_buffer_add(target, source->length + 1);
......@@ -328,9 +358,11 @@ txt_fromwire(isc_buffer_t *source, isc_buffer_t *target) {
isc_region_t tregion;
isc_buffer_active(source, &sregion);
if (sregion.length == 0)
return(DNS_R_UNEXPECTEDEND);
n = *sregion.base + 1;
if (n > sregion.length)
return (DNS_R_UNKNOWN);
return (DNS_R_UNEXPECTEDEND);
isc_buffer_available(target, &tregion);
if (n > tregion.length)
......@@ -396,6 +428,7 @@ buffer_fromregion(isc_buffer_t *buffer, isc_region_t *region,
isc_buffer_init(buffer, region->base, region->length, type);
isc_buffer_add(buffer, region->length);
isc_buffer_setactive(buffer, region->length);
}
static isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cname_5.c,v 1.3 1999/01/19 06:49:29 marka Exp $ */
/* $Id: cname_5.c,v 1.4 1999/01/20 05:20:19 marka Exp $ */
#ifndef RDATA_GENERIC_CNAME_5_H
#define RDATA_GENERIC_CNAME_5_H
......@@ -27,15 +27,21 @@ fromtext_cname(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
INSIST(type == 5);
REQUIRE(type == 5);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, 0, &token) != ISC_R_SUCCESS)
return (DNS_R_UNKNOWN);
if (token.type != isc_tokentype_string)
return (DNS_R_UNKNOWN);
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......@@ -51,7 +57,7 @@ totext_cname(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
dns_name_t prefix;
isc_boolean_t sub;
INSIST(rdata->type == 5);
REQUIRE(rdata->type == 5);
dns_name_init(&name, NULL);
dns_name_init(&prefix, NULL);
......@@ -70,7 +76,7 @@ fromwire_cname(dns_rdataclass_t class, dns_rdatatype_t type,
isc_boolean_t downcase, isc_buffer_t *target) {
dns_name_t name;
INSIST(type == 5);
REQUIRE(type == 5);
class = class; /*unused*/
dns_name_init(&name, NULL);
......@@ -82,7 +88,7 @@ towire_cname(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
dns_name_t name;
isc_region_t region;
INSIST(rdata->type == 5);
REQUIRE(rdata->type == 5);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &region);
......@@ -98,9 +104,9 @@ compare_cname(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
isc_region_t region1;
isc_region_t region2;
INSIST(rdata1->type == rdata2->type);
INSIST(rdata1->class == rdata2->class);
INSIST(rdata1->type == 5);
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->class == rdata2->class);
REQUIRE(rdata1->type == 5);
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
......@@ -118,7 +124,7 @@ static dns_result_t
fromstruct_cname(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
isc_buffer_t *target) {
INSIST(type == 5);
REQUIRE(type == 5);
class = class; /*unused*/
......@@ -131,7 +137,7 @@ fromstruct_cname(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
static dns_result_t
tostruct_cname(dns_rdata_t *rdata, void *target) {
INSIST(rdata->type == 5);
REQUIRE(rdata->type == 5);
target = target;
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cname_5.h,v 1.3 1999/01/19 06:49:29 marka Exp $ */
/* $Id: cname_5.h,v 1.4 1999/01/20 05:20:19 marka Exp $ */
#ifndef RDATA_GENERIC_CNAME_5_H
#define RDATA_GENERIC_CNAME_5_H
......@@ -27,15 +27,21 @@ fromtext_cname(dns_rdataclass_t class, dns_rdatatype_t type,
isc_token_t token;
dns_name_t name;
isc_buffer_t buffer;
unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF;
INSIST(type == 5);
REQUIRE(type == 5);
class = class; /*unused*/
if (isc_lex_gettoken(lexer, 0, &token) != ISC_R_SUCCESS)
return (DNS_R_UNKNOWN);
if (token.type != isc_tokentype_string)
return (DNS_R_UNKNOWN);
if (isc_lex_gettoken(lexer, options, &token) != ISC_R_SUCCESS)
return (DNS_R_UNEXPECTED);
if (token.type != isc_tokentype_string) {
isc_lex_ungettoken(lexer, &token);
if (token.type == isc_tokentype_eol ||
token.type == isc_tokentype_eof)
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTED);
}
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
......@@ -51,7 +57,7 @@ totext_cname(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
dns_name_t prefix;
isc_boolean_t sub;
INSIST(rdata->type == 5);
REQUIRE(rdata->type == 5);
dns_name_init(&name, NULL);
dns_name_init(&prefix, NULL);
......@@ -70,7 +76,7 @@ fromwire_cname(dns_rdataclass_t class, dns_rdatatype_t type,
isc_boolean_t downcase, isc_buffer_t *target) {
dns_name_t name;
INSIST(type == 5);
REQUIRE(type == 5);
class = class; /*unused*/
dns_name_init(&name, NULL);
......@@ -82,7 +88,7 @@ towire_cname(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
dns_name_t name;
isc_region_t region;
INSIST(rdata->type == 5);
REQUIRE(rdata->type == 5);