mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-19 18:48:54 -04:00
Limit isccc_cc_fromwire recursion depth
Named and rndc do not need a lot of recursion so the depth is set to 10.
This commit is contained in:
parent
4537578e78
commit
c4fac5ca98
3 changed files with 35 additions and 12 deletions
|
|
@ -54,6 +54,10 @@
|
|||
|
||||
#define MAX_TAGS 256
|
||||
#define DUP_LIFETIME 900
|
||||
#ifndef ISCCC_MAXDEPTH
|
||||
#define ISCCC_MAXDEPTH \
|
||||
10 /* Big enough for rndc which just sends a string each way. */
|
||||
#endif
|
||||
|
||||
typedef isccc_sexpr_t *sexpr_ptr;
|
||||
|
||||
|
|
@ -486,19 +490,25 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length,
|
|||
|
||||
static isc_result_t
|
||||
table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
||||
uint32_t algorithm, isccc_sexpr_t **alistp);
|
||||
uint32_t algorithm, unsigned int depth, isccc_sexpr_t **alistp);
|
||||
|
||||
static isc_result_t
|
||||
list_fromwire(isccc_region_t *source, isccc_sexpr_t **listp);
|
||||
list_fromwire(isccc_region_t *source, unsigned int depth,
|
||||
isccc_sexpr_t **listp);
|
||||
|
||||
static isc_result_t
|
||||
value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) {
|
||||
value_fromwire(isccc_region_t *source, unsigned int depth,
|
||||
isccc_sexpr_t **valuep) {
|
||||
unsigned int msgtype;
|
||||
uint32_t len;
|
||||
isccc_sexpr_t *value;
|
||||
isccc_region_t active;
|
||||
isc_result_t result;
|
||||
|
||||
if (depth > ISCCC_MAXDEPTH) {
|
||||
return (ISCCC_R_MAXDEPTH);
|
||||
}
|
||||
|
||||
if (REGION_SIZE(*source) < 1 + 4) {
|
||||
return (ISC_R_UNEXPECTEDEND);
|
||||
}
|
||||
|
|
@ -519,9 +529,9 @@ value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) {
|
|||
result = ISC_R_NOMEMORY;
|
||||
}
|
||||
} else if (msgtype == ISCCC_CCMSGTYPE_TABLE) {
|
||||
result = table_fromwire(&active, NULL, 0, valuep);
|
||||
result = table_fromwire(&active, NULL, 0, depth + 1, valuep);
|
||||
} else if (msgtype == ISCCC_CCMSGTYPE_LIST) {
|
||||
result = list_fromwire(&active, valuep);
|
||||
result = list_fromwire(&active, depth + 1, valuep);
|
||||
} else {
|
||||
result = ISCCC_R_SYNTAX;
|
||||
}
|
||||
|
|
@ -531,7 +541,7 @@ value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) {
|
|||
|
||||
static isc_result_t
|
||||
table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
||||
uint32_t algorithm, isccc_sexpr_t **alistp) {
|
||||
uint32_t algorithm, unsigned int depth, isccc_sexpr_t **alistp) {
|
||||
char key[256];
|
||||
uint32_t len;
|
||||
isc_result_t result;
|
||||
|
|
@ -541,6 +551,10 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|||
|
||||
REQUIRE(alistp != NULL && *alistp == NULL);
|
||||
|
||||
if (depth > ISCCC_MAXDEPTH) {
|
||||
return (ISCCC_R_MAXDEPTH);
|
||||
}
|
||||
|
||||
checksum_rstart = NULL;
|
||||
first_tag = true;
|
||||
alist = isccc_alist_create();
|
||||
|
|
@ -557,7 +571,7 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret,
|
|||
GET_MEM(key, len, source->rstart);
|
||||
key[len] = '\0'; /* Ensure NUL termination. */
|
||||
value = NULL;
|
||||
result = value_fromwire(source, &value);
|
||||
result = value_fromwire(source, depth + 1, &value);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto bad;
|
||||
}
|
||||
|
|
@ -595,14 +609,19 @@ bad:
|
|||
}
|
||||
|
||||
static isc_result_t
|
||||
list_fromwire(isccc_region_t *source, isccc_sexpr_t **listp) {
|
||||
list_fromwire(isccc_region_t *source, unsigned int depth,
|
||||
isccc_sexpr_t **listp) {
|
||||
isccc_sexpr_t *list, *value;
|
||||
isc_result_t result;
|
||||
|
||||
if (depth > ISCCC_MAXDEPTH) {
|
||||
return (ISCCC_R_MAXDEPTH);
|
||||
}
|
||||
|
||||
list = NULL;
|
||||
while (!REGION_EMPTY(*source)) {
|
||||
value = NULL;
|
||||
result = value_fromwire(source, &value);
|
||||
result = value_fromwire(source, depth + 1, &value);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isccc_sexpr_free(&list);
|
||||
return (result);
|
||||
|
|
@ -634,7 +653,7 @@ isccc_cc_fromwire(isccc_region_t *source, isccc_sexpr_t **alistp,
|
|||
return (ISCCC_R_UNKNOWNVERSION);
|
||||
}
|
||||
|
||||
return (table_fromwire(source, secret, algorithm, alistp));
|
||||
return (table_fromwire(source, secret, algorithm, 0, alistp));
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
|
|
|
|||
|
|
@ -35,8 +35,10 @@
|
|||
#define ISCCC_R_CLOCKSKEW (ISC_RESULTCLASS_ISCCC + 4)
|
||||
/*% Duplicate */
|
||||
#define ISCCC_R_DUPLICATE (ISC_RESULTCLASS_ISCCC + 5)
|
||||
/*% Maximum recursion depth */
|
||||
#define ISCCC_R_MAXDEPTH (ISC_RESULTCLASS_ISCCC + 6)
|
||||
|
||||
#define ISCCC_R_NRESULTS 6 /*%< Number of results */
|
||||
#define ISCCC_R_NRESULTS 7 /*%< Number of results */
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -25,12 +25,14 @@ static const char *text[ISCCC_R_NRESULTS] = {
|
|||
"bad auth", /* 3 */
|
||||
"expired", /* 4 */
|
||||
"clock skew", /* 5 */
|
||||
"duplicate" /* 6 */
|
||||
"duplicate", /* 6 */
|
||||
"max depth" /* 7 */
|
||||
};
|
||||
|
||||
static const char *ids[ISCCC_R_NRESULTS] = {
|
||||
"ISCCC_R_UNKNOWNVERSION", "ISCCC_R_SYNTAX", "ISCCC_R_BADAUTH",
|
||||
"ISCCC_R_EXPIRED", "ISCCC_R_CLOCKSKEW", "ISCCC_R_DUPLICATE",
|
||||
"ISCCC_R_MAXDEPTH"
|
||||
};
|
||||
|
||||
#define ISCCC_RESULT_RESULTSET 2
|
||||
|
|
|
|||
Loading…
Reference in a new issue