File bind-CVE-2023-3341.patch of Package bind.37294
Index: bind-9.9.9-P1/lib/isccc/cc.c
===================================================================
--- bind-9.9.9-P1.orig/lib/isccc/cc.c
+++ bind-9.9.9-P1/lib/isccc/cc.c
@@ -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;
@@ -319,19 +323,26 @@ verify(isccc_sexpr_t *alist, unsigned ch
static isc_result_t
table_fromwire(isccc_region_t *source, isccc_region_t *secret,
- isccc_sexpr_t **alistp);
+ 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;
isc_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);
GET8(msgtype, source->rstart);
@@ -349,9 +360,9 @@ value_fromwire(isccc_region_t *source, i
} else
result = ISC_R_NOMEMORY;
} else if (msgtype == ISCCC_CCMSGTYPE_TABLE)
- result = table_fromwire(&active, NULL, valuep);
+ result = table_fromwire(&active, NULL, 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;
@@ -360,7 +371,7 @@ value_fromwire(isccc_region_t *source, i
static isc_result_t
table_fromwire(isccc_region_t *source, isccc_region_t *secret,
- isccc_sexpr_t **alistp)
+ unsigned int depth, isccc_sexpr_t **alistp)
{
char key[256];
isc_uint32_t len;
@@ -371,6 +382,10 @@ table_fromwire(isccc_region_t *source, i
REQUIRE(alistp != NULL && *alistp == NULL);
+ if (depth > ISCCC_MAXDEPTH) {
+ return (ISCCC_R_MAXDEPTH);
+ }
+
checksum_rstart = NULL;
first_tag = ISC_TRUE;
alist = isccc_alist_create();
@@ -386,7 +401,7 @@ table_fromwire(isccc_region_t *source, i
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;
if (isccc_alist_define(alist, key, value) == NULL) {
@@ -419,14 +434,20 @@ table_fromwire(isccc_region_t *source, i
}
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);
@@ -457,7 +478,7 @@ isccc_cc_fromwire(isccc_region_t *source
if (version != 1)
return (ISCCC_R_UNKNOWNVERSION);
- return (table_fromwire(source, secret, alistp));
+ return (table_fromwire(source, secret, 0, alistp));
}
static isc_result_t
Index: bind-9.9.9-P1/lib/isccc/include/isccc/result.h
===================================================================
--- bind-9.9.9-P1.orig/lib/isccc/include/isccc/result.h
+++ bind-9.9.9-P1/lib/isccc/include/isccc/result.h
@@ -54,8 +54,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
Index: bind-9.9.9-P1/lib/isccc/result.c
===================================================================
--- bind-9.9.9-P1.orig/lib/isccc/result.c
+++ bind-9.9.9-P1/lib/isccc/result.c
@@ -47,7 +47,8 @@ static const char *text[ISCCC_R_NRESULTS
"bad auth", /* 3 */
"expired", /* 4 */
"clock skew", /* 5 */
- "duplicate" /* 6 */
+ "duplicate", /* 6 */
+ "max depth" /* 7 */
};
#define ISCCC_RESULT_RESULTSET 2