b30d9d
--- db-18.1.32/src/btree/bt_cursor.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/btree/bt_cursor.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -282,6 +282,8 @@
b30d9d
 	 *
b30d9d
 	 * Recno uses the btree bt_ovflsize value -- it's close enough.
b30d9d
 	 */
b30d9d
+	if (t->bt_minkey == 0)
b30d9d
+		return (DB_RECOVER);
b30d9d
 	cp->ovflsize = B_MINKEY_TO_OVFLSIZE(
b30d9d
 	    dbp,  F_ISSET(dbc, DBC_OPD) ? 2 : t->bt_minkey, dbp->pgsize);
b30d9d
 
b30d9d
--- db-18.1.32/src/btree/bt_verify.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/btree/bt_verify.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -700,7 +700,11 @@
b30d9d
 			isbad = 1;
b30d9d
 			goto err;
b30d9d
 		default:
b30d9d
+			if (ret == 0) {
b30d9d
+				isbad = 1;
b30d9d
+				ret = DB_VERIFY_FATAL;
b30d9d
+				goto err;
b30d9d
+			}
b30d9d
-			DB_ASSERT(env, ret != 0);
b30d9d
 			break;
b30d9d
 		}
b30d9d
 
b30d9d
@@ -1074,7 +1078,7 @@
b30d9d
 	DBT dbta, dbtb, dup_1, dup_2, *p1, *p2, *tmp;
b30d9d
 	ENV *env;
b30d9d
 	PAGE *child;
b30d9d
+	db_pgno_t cpgno, grandparent;
b30d9d
-	db_pgno_t cpgno;
b30d9d
 	VRFY_PAGEINFO *pip;
b30d9d
 	db_indx_t i, *inp;
b30d9d
 	int adj, cmp, freedup_1, freedup_2, isbad, ret, t_ret;
b30d9d
@@ -1106,7 +1110,8 @@
b30d9d
 
b30d9d
 	buf1 = buf2 = NULL;
b30d9d
 
b30d9d
+	if (LF_ISSET(DB_NOORDERCHK))
b30d9d
+		return (EINVAL);
b30d9d
-	DB_ASSERT(env, !LF_ISSET(DB_NOORDERCHK));
b30d9d
 
b30d9d
 	dupfunc = (dbp->dup_compare == NULL) ? __bam_defcmp : dbp->dup_compare;
b30d9d
 	if (TYPE(h) == P_LDUP)
b30d9d
@@ -1115,6 +1120,7 @@
b30d9d
 		func = __bam_defcmp;
b30d9d
 		if (dbp->bt_internal != NULL) {
b30d9d
 			bt = (BTREE *)dbp->bt_internal;
b30d9d
+			grandparent = bt->bt_root;
b30d9d
 			if (TYPE(h) == P_IBTREE && (bt->bt_compare != NULL ||
b30d9d
 			    dupfunc != __bam_defcmp)) {
b30d9d
 				/*
b30d9d
@@ -974,8 +980,24 @@
b30d9d
 				 */
b30d9d
 				mpf = dbp->mpf;
b30d9d
 				child = h;
b30d9d
+				cpgno = pgno;
b30d9d
 				while (TYPE(child) == P_IBTREE) {
b30d9d
+					if (NUM_ENT(child) == 0) {
b30d9d
+						EPRINT((env, DB_STR_A("1088",
b30d9d
+		    "Page %lu: internal page is empty and should not be",
b30d9d
+					    "%lu"), (u_long)cpgno));
b30d9d
+						ret = DB_VERIFY_BAD;
b30d9d
+						goto err;
b30d9d
+					}
b30d9d
 					bi = GET_BINTERNAL(dbp, child, 0);
b30d9d
+					if (grandparent == bi->pgno) {
b30d9d
+						EPRINT((env, DB_STR_A("5552",
b30d9d
+					      "Page %lu: found twice in the btree",
b30d9d
+				          "%lu"), (u_long)grandparent));
b30d9d
+						ret = DB_VERIFY_FATAL;
b30d9d
+						goto err;
b30d9d
+					} else
b30d9d
+						grandparent = cpgno;
b30d9d
 					cpgno = bi->pgno;
b30d9d
 					if (child != h &&
b30d9d
 					    (ret = __memp_fput(mpf,
b30d9d
@@ -1402,7 +1416,10 @@
b30d9d
 					 */
b30d9d
 					if (dup_1.data == NULL ||
b30d9d
 					    dup_2.data == NULL) {
b30d9d
+						if (ovflok) {
b30d9d
+							isbad = 1;
b30d9d
+							goto err;
b30d9d
+						}
b30d9d
-						DB_ASSERT(env, !ovflok);
b30d9d
 						if (pip != NULL)
b30d9d
 							F_SET(pip,
b30d9d
 							    VRFY_INCOMPLETE);
b30d9d
@@ -1747,9 +1764,10 @@
b30d9d
 			    (ret = __db_vrfy_ovfl_structure(dbp, vdp,
b30d9d
 			    child->pgno, child->tlen,
b30d9d
 			    flags | DB_ST_OVFL_LEAF)) != 0) {
b30d9d
+				if (ret == DB_VERIFY_BAD) {
b30d9d
-				if (ret == DB_VERIFY_BAD)
b30d9d
 					isbad = 1;
b30d9d
+					break;
b30d9d
+				} else
b30d9d
-				else
b30d9d
 					goto done;
b30d9d
 			}
b30d9d
 
b30d9d
@@ -1823,9 +1841,10 @@
b30d9d
 						    stflags | DB_ST_TOPLEVEL,
b30d9d
 						    NULL, NULL, NULL)) != 0) {
b30d9d
 							if (ret ==
b30d9d
+							    DB_VERIFY_BAD) {
b30d9d
-							    DB_VERIFY_BAD)
b30d9d
 								isbad = 1;
b30d9d
+								break;
b30d9d
+							} else
b30d9d
-							else
b30d9d
 								goto err;
b30d9d
 						}
b30d9d
 					}
b30d9d
@@ -1969,7 +1988,10 @@
b30d9d
 			 */
b30d9d
 
b30d9d
 			/* Otherwise, __db_vrfy_childput would be broken. */
b30d9d
+			if (child->refcnt < 1) {
b30d9d
+				isbad = 1;
b30d9d
+				goto err;
b30d9d
+			}
b30d9d
-			DB_ASSERT(env, child->refcnt >= 1);
b30d9d
 
b30d9d
 			/*
b30d9d
 			 * An overflow referenced more than twice here
b30d9d
@@ -1986,9 +2008,10 @@
b30d9d
 					if ((ret = __db_vrfy_ovfl_structure(dbp,
b30d9d
 					    vdp, child->pgno, child->tlen,
b30d9d
 					    flags)) != 0) {
b30d9d
+						if (ret == DB_VERIFY_BAD) {
b30d9d
-						if (ret == DB_VERIFY_BAD)
b30d9d
 							isbad = 1;
b30d9d
+							break;
b30d9d
+						} else
b30d9d
-						else
b30d9d
 							goto done;
b30d9d
 					}
b30d9d
 		}
b30d9d
@@ -2026,9 +2049,10 @@
b30d9d
 		if ((ret = __bam_vrfy_subtree(dbp, vdp, li->pgno,
b30d9d
 		    i == 0 ? NULL : li, ri, flags, &child_level,
b30d9d
 		    &child_nrecs, NULL)) != 0) {
b30d9d
+			if (ret == DB_VERIFY_BAD) {
b30d9d
-			if (ret == DB_VERIFY_BAD)
b30d9d
 				isbad = 1;
b30d9d
+				break;
b30d9d
+			} else
b30d9d
-			else
b30d9d
 				goto done;
b30d9d
 		}
b30d9d
 
b30d9d
@@ -2929,7 +2953,11 @@
b30d9d
 	db_pgno_t current, p;
b30d9d
 	int err_ret, ret;
b30d9d
 
b30d9d
+	if (pgset == NULL) {
b30d9d
+		EPRINT((dbp->env, DB_STR("5542",
b30d9d
+			"Error, database contains no visible pages.")));
b30d9d
+		return (DB_RUNRECOVERY);
b30d9d
+	}
b30d9d
-	DB_ASSERT(dbp->env, pgset != NULL);
b30d9d
 
b30d9d
 	mpf = dbp->mpf;
b30d9d
 	h = NULL;
b30d9d
--- db-18.1.32/src/db/db_conv.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/db/db_conv.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -493,8 +493,11 @@
b30d9d
 	db_indx_t i, *inp, len, tmp;
b30d9d
 	u_int8_t *end, *p, *pgend;
b30d9d
 
b30d9d
-	if (pagesize == 0)
b30d9d
-		return (0);
b30d9d
+	/* This function is also used to byteswap logs, so
b30d9d
+	 * the pagesize might not be an actual page size.
b30d9d
+	 */
b30d9d
+	if (!(pagesize >= 24 && pagesize <= DB_MAX_PGSIZE))
b30d9d
+		return (EINVAL);
b30d9d
 
b30d9d
 	if (pgin) {
b30d9d
 		M_32_SWAP(h->lsn.file);
b30d9d
@@ -513,26 +516,41 @@
b30d9d
 	pgend = (u_int8_t *)h + pagesize;
b30d9d
 
b30d9d
 	inp = P_INP(dbp, h);
b30d9d
-	if ((u_int8_t *)inp >= pgend)
b30d9d
-		goto out;
b30d9d
+	if ((u_int8_t *)inp > pgend)
b30d9d
+		return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
 	switch (TYPE(h)) {
b30d9d
 	case P_HASH_UNSORTED:
b30d9d
 	case P_HASH:
b30d9d
 		for (i = 0; i < NUM_ENT(h); i++) {
b30d9d
+			if ((u_int8_t*)(inp + i) >= pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
+			if (inp[i] == 0)
b30d9d
+				continue;
b30d9d
 			if (pgin)
b30d9d
 				M_16_SWAP(inp[i]);
b30d9d
+			if (inp[i] >= pagesize)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
-			if (P_ENTRY(dbp, h, i) >= pgend)
b30d9d
-				continue;
b30d9d
+	   		if (P_ENTRY(dbp, h, i) >= pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
 			switch (HPAGE_TYPE(dbp, h, i)) {
b30d9d
 			case H_KEYDATA:
b30d9d
 				break;
b30d9d
 			case H_DUPLICATE:
b30d9d
+				if (LEN_HITEM(dbp, h, pagesize, i) < 
b30d9d
+				    HKEYDATA_SIZE(0))
b30d9d
+					return (__db_pgfmt(env, pg));
b30d9d
+
b30d9d
 				len = LEN_HKEYDATA(dbp, h, pagesize, i);
b30d9d
 				p = HKEYDATA_DATA(P_ENTRY(dbp, h, i));
b30d9d
-				for (end = p + len; p < end;) {
b30d9d
+
b30d9d
+				end = p + len;
b30d9d
+				if (end > pgend)
b30d9d
+					return (__db_pgfmt(env, pg));
b30d9d
+
b30d9d
+				while (p < end) {
b30d9d
 					if (pgin) {
b30d9d
 						P_16_SWAP(p);
b30d9d
 						memcpy(&tmp,
b30d9d
@@ -544,14 +562,20 @@
b30d9d
 						SWAP16(p);
b30d9d
 					}
b30d9d
 					p += tmp;
b30d9d
+					if (p >= end)
b30d9d
+						return (__db_pgfmt(env, pg));
b30d9d
 					SWAP16(p);
b30d9d
 				}
b30d9d
 				break;
b30d9d
 			case H_OFFDUP:
b30d9d
+				if ((inp[i] + HOFFDUP_SIZE) > pagesize)
b30d9d
+					return (__db_pgfmt(env, pg));
b30d9d
 				p = HOFFPAGE_PGNO(P_ENTRY(dbp, h, i));
b30d9d
 				SWAP32(p);			/* pgno */
b30d9d
 				break;
b30d9d
 			case H_OFFPAGE:
b30d9d
+				if ((inp[i] + HOFFPAGE_SIZE) > pagesize)
b30d9d
+					return (__db_pgfmt(env, pg));
b30d9d
 				p = HOFFPAGE_PGNO(P_ENTRY(dbp, h, i));
b30d9d
 				SWAP32(p);			/* pgno */
b30d9d
 				SWAP32(p);			/* tlen */
b30d9d
@@ -559,7 +583,6 @@
b30d9d
 			default:
b30d9d
 				return (__db_pgfmt(env, pg));
b30d9d
 			}
b30d9d
-
b30d9d
 		}
b30d9d
 
b30d9d
 		/*
b30d9d
@@ -576,8 +599,12 @@
b30d9d
 	case P_LDUP:
b30d9d
 	case P_LRECNO:
b30d9d
 		for (i = 0; i < NUM_ENT(h); i++) {
b30d9d
+			if ((u_int8_t *)(inp + i) >= pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 			if (pgin)
b30d9d
 				M_16_SWAP(inp[i]);
b30d9d
+			if (inp[i] >= pagesize)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
 			/*
b30d9d
 			 * In the case of on-page duplicates, key information
b30d9d
@@ -597,7 +624,7 @@
b30d9d
 
b30d9d
 			bk = GET_BKEYDATA(dbp, h, i);
b30d9d
 			if ((u_int8_t *)bk >= pgend)
b30d9d
-				continue;
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 			switch (B_TYPE(bk->type)) {
b30d9d
 			case B_KEYDATA:
b30d9d
 				M_16_SWAP(bk->len);
b30d9d
@@ -605,6 +632,8 @@
b30d9d
 			case B_DUPLICATE:
b30d9d
 			case B_OVERFLOW:
b30d9d
 				bo = (BOVERFLOW *)bk;
b30d9d
+				if (((u_int8_t *)bo + BOVERFLOW_SIZE) > pgend)
b30d9d
+					return (__db_pgfmt(env, pg));
b30d9d
 				M_32_SWAP(bo->pgno);
b30d9d
 				M_32_SWAP(bo->tlen);
b30d9d
 				break;
b30d9d
@@ -618,12 +647,17 @@
b30d9d
 		break;
b30d9d
 	case P_IBTREE:
b30d9d
 		for (i = 0; i < NUM_ENT(h); i++) {
b30d9d
+			if ((u_int8_t *)(inp + i) > pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 			if (pgin)
b30d9d
 				M_16_SWAP(inp[i]);
b30d9d
+			if ((u_int16_t)(inp[i] + 
b30d9d
+			    BINTERNAL_SIZE(0) - 1) > pagesize)
b30d9d
+				break;
b30d9d
 
b30d9d
 			bi = GET_BINTERNAL(dbp, h, i);
b30d9d
-			if ((u_int8_t *)bi >= pgend)
b30d9d
-				continue;
b30d9d
+			if (((u_int8_t *)bi + BINTERNAL_SIZE(0)) > pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
 			M_16_SWAP(bi->len);
b30d9d
 			M_32_SWAP(bi->pgno);
b30d9d
@@ -634,6 +668,10 @@
b30d9d
 				break;
b30d9d
 			case B_DUPLICATE:
b30d9d
 			case B_OVERFLOW:
b30d9d
+				if ((u_int16_t)(inp[i] + 
b30d9d
+				    BINTERNAL_SIZE(BOVERFLOW_SIZE) - 1) >
b30d9d
+				    pagesize)
b30d9d
+					goto out;
b30d9d
 				bo = (BOVERFLOW *)bi->data;
b30d9d
 				M_32_SWAP(bo->pgno);
b30d9d
 				M_32_SWAP(bo->tlen);
b30d9d
@@ -648,12 +686,16 @@
b30d9d
 		break;
b30d9d
 	case P_IRECNO:
b30d9d
 		for (i = 0; i < NUM_ENT(h); i++) {
b30d9d
+			if ((u_int8_t *)(inp + i) >= pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 			if (pgin)
b30d9d
 				M_16_SWAP(inp[i]);
b30d9d
+			if (inp[i] >= pagesize)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
 			ri = GET_RINTERNAL(dbp, h, i);
b30d9d
-			if ((u_int8_t *)ri >= pgend)
b30d9d
-				continue;
b30d9d
+			if ((((u_int8_t *)ri) + RINTERNAL_SIZE) > pgend)
b30d9d
+				return (__db_pgfmt(env, pg));
b30d9d
 
b30d9d
 			M_32_SWAP(ri->pgno);
b30d9d
 			M_32_SWAP(ri->nrecs);
b30d9d
--- db-18.1.32/src/db/db_vrfy.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/db/db_vrfy.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -381,8 +381,10 @@
b30d9d
 		    vdp, name, 0, lp, rp, flags)) != 0) {
b30d9d
 			if (t_ret == DB_VERIFY_BAD)
b30d9d
 				isbad = 1;
b30d9d
+			else {
b30d9d
+			    ret = t_ret;
b30d9d
+			    goto err;
b30d9d
+			}
b30d9d
-			else
b30d9d
-				goto err;
b30d9d
 		}
b30d9d
 
b30d9d
 	/*
b30d9d
@@ -771,9 +773,10 @@
b30d9d
 		 */
b30d9d
 		if ((t_ret = __memp_fget(mpf, &i,
b30d9d
 		    vdp->thread_info, NULL, 0, &h)) != 0) {
b30d9d
+			if ((dbp->type == DB_HASH ||
b30d9d
-			if (dbp->type == DB_HASH ||
b30d9d
 			    (dbp->type == DB_QUEUE &&
b30d9d
+			    F_ISSET(dbp, DB_AM_INMEM))) &&
b30d9d
+			    t_ret != DB_RUNRECOVERY) {
b30d9d
-			    F_ISSET(dbp, DB_AM_INMEM))) {
b30d9d
 				if ((t_ret =
b30d9d
 				    __db_vrfy_getpageinfo(vdp, i, &pip)) != 0)
b30d9d
 					goto err1;
b30d9d
@@ -945,6 +948,8 @@
b30d9d
 			return (ret == 0 ? t_ret : ret);
b30d9d
 	}
b30d9d
 
b30d9d
+	if (ret == DB_PAGE_NOTFOUND && isbad == 1)
b30d9d
+		ret = 0;
b30d9d
 	return ((isbad == 1 && ret == 0) ? DB_VERIFY_BAD : ret);
b30d9d
 }
b30d9d
 
b30d9d
@@ -1581,7 +1586,7 @@
b30d9d
 	if (pgno == PGNO_BASE_MD &&
b30d9d
 	    dbtype != DB_QUEUE && meta->last_pgno != vdp->last_pgno) {
b30d9d
 #ifdef HAVE_FTRUNCATE
b30d9d
+		ret = DB_VERIFY_FATAL;
b30d9d
-		isbad = 1;
b30d9d
 		EPRINT((env, DB_STR_A("0552",
b30d9d
 		    "Page %lu: last_pgno is not correct: %lu != %lu",
b30d9d
 		    "%lu %lu %lu"), (u_long)pgno,
b30d9d
@@ -1622,7 +1627,11 @@
b30d9d
 
b30d9d
 	env = dbp->env;
b30d9d
 	pgset = vdp->pgset;
b30d9d
+	if (pgset == NULL) {
b30d9d
+		EPRINT((env, DB_STR("5543",
b30d9d
+			"Error, database contains no visible pages.")));
b30d9d
+		return (DB_RUNRECOVERY);
b30d9d
+	}
b30d9d
-	DB_ASSERT(env, pgset != NULL);
b30d9d
 
b30d9d
 	if ((ret = __db_vrfy_getpageinfo(vdp, meta, &pip)) != 0)
b30d9d
 		return (ret);
b30d9d
@@ -2014,7 +2023,8 @@
b30d9d
 	int keyflag, ret, t_ret;
b30d9d
 
b30d9d
 	env = dbp->env;
b30d9d
+	if (!LF_ISSET(DB_SALVAGE))
b30d9d
+		return (EINVAL);
b30d9d
-	DB_ASSERT(env, LF_ISSET(DB_SALVAGE));
b30d9d
 
b30d9d
 	/*
b30d9d
 	 * !!!
b30d9d
@@ -2126,10 +2136,8 @@
b30d9d
 	int (*callback) __P((void *, const void *));
b30d9d
 	u_int32_t flags;
b30d9d
 {
b30d9d
-	ENV *env;
b30d9d
-
b30d9d
-	env = dbp->env;
b30d9d
-	DB_ASSERT(env, LF_ISSET(DB_SALVAGE));
b30d9d
+	if (!LF_ISSET(DB_SALVAGE))
b30d9d
+		return (EINVAL);
b30d9d
 
b30d9d
 	/* If we got this page in the subdb pass, we can safely skip it. */
b30d9d
 	if (__db_salvage_isdone(vdp, pgno))
b30d9d
@@ -2242,8 +2253,8 @@
b30d9d
 				ret = t_ret;
b30d9d
 			break;
b30d9d
 		case SALVAGE_OVERFLOW:
b30d9d
+			EPRINT((env, DB_STR("5544", "Invalid page type to salvage.")));
b30d9d
+			return (EINVAL);
b30d9d
-			DB_ASSERT(env, 0);	/* Shouldn't ever happen. */
b30d9d
-			break;
b30d9d
 		case SALVAGE_HASH:
b30d9d
 			if ((t_ret = __ham_salvage(dbp, vdp,
b30d9d
 			    pgno, h, handle, callback, flags)) != 0 && ret == 0)
b30d9d
@@ -2256,8 +2267,8 @@
b30d9d
 			 * Shouldn't happen, but if it does, just do what the
b30d9d
 			 * nice man says.
b30d9d
 			 */
b30d9d
+			EPRINT((env, DB_STR("5545", "Invalid page type to salvage.")));
b30d9d
+			return (EINVAL);
b30d9d
-			DB_ASSERT(env, 0);
b30d9d
-			break;
b30d9d
 		}
b30d9d
 		if ((t_ret = __memp_fput(mpf,
b30d9d
 		    vdp->thread_info, h, dbp->priority)) != 0 && ret == 0)
b30d9d
@@ -2303,8 +2314,8 @@
b30d9d
 					ret = t_ret;
b30d9d
 			break;
b30d9d
 		default:
b30d9d
+			EPRINT((env, DB_STR("5546", "Invalid page type to salvage.")));
b30d9d
+			return (EINVAL);
b30d9d
-			DB_ASSERT(env, 0);	/* Shouldn't ever happen. */
b30d9d
-			break;
b30d9d
 		}
b30d9d
 		if ((t_ret = __memp_fput(mpf,
b30d9d
 		    vdp->thread_info, h, dbp->priority)) != 0 && ret == 0)
b30d9d
@@ -2361,7 +2372,10 @@
b30d9d
 
b30d9d
 	env = dbp->env;
b30d9d
 
b30d9d
+	if (himarkp == NULL) {
b30d9d
+		__db_msg(env, "Page %lu index has no end.", (u_long)pgno);
b30d9d
+		return (DB_VERIFY_FATAL);
b30d9d
+	}
b30d9d
-	DB_ASSERT(env, himarkp != NULL);
b30d9d
 	inp = P_INP(dbp, h);
b30d9d
 
b30d9d
 	/*
b30d9d
@@ -2783,7 +2797,11 @@
b30d9d
 					goto err;
b30d9d
 				ovfl_bufsz = bkkey->len + 1;
b30d9d
 			}
b30d9d
+			if (subdbname == NULL) {
b30d9d
+				EPRINT((env, DB_STR("5547", "Subdatabase cannot be null.")));
b30d9d
+				ret = EINVAL;
b30d9d
+				goto err;
b30d9d
+			}
b30d9d
-			DB_ASSERT(env, subdbname != NULL);
b30d9d
 			memcpy(subdbname, bkkey->data, bkkey->len);
b30d9d
 			subdbname[bkkey->len] = '\0';
b30d9d
 		}
b30d9d
--- db-18.1.32/src/db/db_vrfyutil.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/db/db_vrfyutil.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -214,7 +214,8 @@
b30d9d
 	if ((ret = __db_get(pgdbp,
b30d9d
 	    vdp->thread_info, vdp->txn, &key, &data, 0)) == 0) {
b30d9d
 		/* Found it. */
b30d9d
+		if (data.size != sizeof(VRFY_PAGEINFO))
b30d9d
+			return (DB_VERIFY_FATAL);
b30d9d
-		DB_ASSERT(env, data.size == sizeof(VRFY_PAGEINFO));
b30d9d
 		pip = data.data;
b30d9d
 		LIST_INSERT_HEAD(&vdp->activepips, pip, links);
b30d9d
 		goto found;
b30d9d
@@ -342,7 +343,8 @@
b30d9d
 	F_SET(&data, DB_DBT_USERMEM);
b30d9d
 
b30d9d
 	if ((ret = __db_get(dbp, ip, txn, &key, &data, 0)) == 0) {
b30d9d
+		if (data.size != sizeof(int))
b30d9d
+			return (EINVAL);
b30d9d
-		DB_ASSERT(dbp->env, data.size == sizeof(int));
b30d9d
 	} else if (ret == DB_NOTFOUND)
b30d9d
 		val = 0;
b30d9d
 	else
b30d9d
@@ -382,7 +384,8 @@
b30d9d
 	F_SET(&data, DB_DBT_USERMEM);
b30d9d
 
b30d9d
 	if ((ret = __db_get(dbp, ip, txn, &key, &data, 0)) == 0) {
b30d9d
+		if (data.size != sizeof(int))
b30d9d
+			return (DB_VERIFY_FATAL);
b30d9d
-		DB_ASSERT(dbp->env, data.size == sizeof(int));
b30d9d
 	} else if (ret != DB_NOTFOUND)
b30d9d
 		return (ret);
b30d9d
 
b30d9d
@@ -419,7 +422,8 @@
b30d9d
 	if ((ret = __dbc_get(dbc, &key, &data, DB_NEXT)) != 0)
b30d9d
 		return (ret);
b30d9d
 
b30d9d
+	if (key.size != sizeof(db_pgno_t))
b30d9d
+		return (DB_VERIFY_FATAL);
b30d9d
-	DB_ASSERT(dbc->env, key.size == sizeof(db_pgno_t));
b30d9d
 	*pgnop = pgno;
b30d9d
 
b30d9d
 	return (0);
b30d9d
@@ -566,7 +570,8 @@
b30d9d
 	if ((ret = __dbc_get(dbc, &key, &data, DB_SET)) != 0)
b30d9d
 		return (ret);
b30d9d
 
b30d9d
+	if (data.size != sizeof(VRFY_CHILDINFO))
b30d9d
+		return (DB_VERIFY_FATAL);
b30d9d
-	DB_ASSERT(dbc->env, data.size == sizeof(VRFY_CHILDINFO));
b30d9d
 	*cipp = (VRFY_CHILDINFO *)data.data;
b30d9d
 
b30d9d
 	return (0);
b30d9d
@@ -594,7 +599,8 @@
b30d9d
 	if ((ret = __dbc_get(dbc, &key, &data, DB_NEXT_DUP)) != 0)
b30d9d
 		return (ret);
b30d9d
 
b30d9d
+	if (data.size != sizeof(VRFY_CHILDINFO))
b30d9d
+		return (DB_VERIFY_FATAL);
b30d9d
-	DB_ASSERT(dbc->env, data.size == sizeof(VRFY_CHILDINFO));
b30d9d
 	*cipp = (VRFY_CHILDINFO *)data.data;
b30d9d
 
b30d9d
 	return (0);
b30d9d
@@ -721,7 +727,8 @@
b30d9d
 		return (ret);
b30d9d
 
b30d9d
 	while ((ret = __dbc_get(*dbcp, &key, &data, DB_NEXT)) == 0) {
b30d9d
+		if (data.size != sizeof(u_int32_t))
b30d9d
+			return (DB_VERIFY_FATAL);
b30d9d
-		DB_ASSERT(dbp->env, data.size == sizeof(u_int32_t));
b30d9d
 		memcpy(&pgtype, data.data, sizeof(pgtype));
b30d9d
 
b30d9d
 		if (skip_overflow && pgtype == SALVAGE_OVERFLOW)
b30d9d
@@ -730,8 +737,9 @@
b30d9d
 		if ((ret = __dbc_del(*dbcp, 0)) != 0)
b30d9d
 			return (ret);
b30d9d
 		if (pgtype != SALVAGE_IGNORE) {
b30d9d
+			if (key.size != sizeof(db_pgno_t)
b30d9d
+				|| data.size != sizeof(u_int32_t))
b30d9d
+				return (DB_VERIFY_FATAL);
b30d9d
-			DB_ASSERT(dbp->env, key.size == sizeof(db_pgno_t));
b30d9d
-			DB_ASSERT(dbp->env, data.size == sizeof(u_int32_t));
b30d9d
 
b30d9d
 			*pgnop = *(db_pgno_t *)key.data;
b30d9d
 			*pgtypep = *(u_int32_t *)data.data;
b30d9d
--- db-18.1.32/src/db/partition.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/db/partition.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -461,9 +461,19 @@
b30d9d
 		} else
b30d9d
 			part->nparts = meta->nparts;
b30d9d
 	} else if (meta->nparts != 0 && part->nparts != meta->nparts) {
b30d9d
+		ret = EINVAL;
b30d9d
 		__db_errx(env, DB_STR("0656",
b30d9d
 		    "Number of partitions does not match."));
b30d9d
-		ret = EINVAL;
b30d9d
+		goto err;
b30d9d
+	}
b30d9d
+	/*
b30d9d
+	 * There is no limit on the number of partitions, but I cannot imagine a real
b30d9d
+	 * database having more than 10000.
b30d9d
+	 */
b30d9d
+	if (meta->nparts > 10000) {
b30d9d
+		ret = EINVAL;
b30d9d
+		__db_errx(env, DB_STR_A("5553",
b30d9d
+			"Too many partitions %lu", "%lu"), (u_long)(meta->nparts));
b30d9d
 		goto err;
b30d9d
 	}
b30d9d
 
b30d9d
@@ -2106,10 +2116,13 @@
b30d9d
 			memcpy(rp->data, key->data, key->size);
b30d9d
 			B_TSET(rp->type, B_KEYDATA);
b30d9d
 		}
b30d9d
+vrfy:   if ((t_ret = __db_verify(*pdbp, ip, (*pdbp)->fname,
b30d9d
+	      NULL, handle, callback,
b30d9d
+	      lp, rp, flags | DB_VERIFY_PARTITION)) != 0 && ret == 0) {
b30d9d
+	        ret = t_ret;
b30d9d
+            if (ret == ENOENT)
b30d9d
+                break;
b30d9d
+	    }
b30d9d
-vrfy:		if ((t_ret = __db_verify(*pdbp, ip, (*pdbp)->fname,
b30d9d
-		    NULL, handle, callback,
b30d9d
-		    lp, rp, flags | DB_VERIFY_PARTITION)) != 0 && ret == 0)
b30d9d
-			ret = t_ret;
b30d9d
 	}
b30d9d
 
b30d9d
 err:	if (lp != NULL)
b30d9d
--- db-18.1.32/src/hash/hash_page.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/hash/hash_page.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -869,7 +869,11 @@
b30d9d
 	/* Validate that next, prev pointers are OK */
b30d9d
 	n = NUM_ENT(p);
b30d9d
 	dbp = dbc->dbp;
b30d9d
+	if (n % 2 != 0) {
b30d9d
+		__db_errx(dbp->env, DB_STR_A("5549",
b30d9d
+		  "Odd number of entries on page: %lu", "%lu"), (u_long)(p->pgno));
b30d9d
+		return (DB_VERIFY_FATAL);
b30d9d
+	}
b30d9d
-	DB_ASSERT(dbp->env, n%2 == 0 );
b30d9d
 
b30d9d
 	env = dbp->env;
b30d9d
 	t = dbp->h_internal;
b30d9d
@@ -940,7 +944,12 @@
b30d9d
 			if ((ret = __db_prpage(dbp, p, DB_PR_PAGE)) != 0)
b30d9d
 				return (ret);
b30d9d
 #endif
b30d9d
+			if (res >= 0) {
b30d9d
+				__db_errx(env, DB_STR_A("5550",
b30d9d
+					"Odd number of entries on page: %lu", "%lu"),
b30d9d
+					(u_long)p->pgno);
b30d9d
+				return (DB_VERIFY_FATAL);
b30d9d
+			}
b30d9d
-			DB_ASSERT(dbp->env, res < 0);
b30d9d
 		}
b30d9d
 
b30d9d
 		prev = curr;
b30d9d
--- db-18.1.32/src/hash/hash_verify.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/hash/hash_verify.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -615,7 +615,7 @@
b30d9d
 				isbad = 1;
b30d9d
 			else
b30d9d
 				goto err;
b30d9d
+		}
b30d9d
-		    }
b30d9d
 
b30d9d
 	/*
b30d9d
 	 * There may be unused hash pages corresponding to buckets
b30d9d
@@ -746,7 +746,7 @@
b30d9d
 		    "Page %lu: impossible first page in bucket %lu", "%lu %lu"),
b30d9d
 		    (u_long)pgno, (u_long)bucket));
b30d9d
 		/* Unsafe to continue. */
b30d9d
+		ret = DB_VERIFY_FATAL;
b30d9d
-		isbad = 1;
b30d9d
 		goto err;
b30d9d
 	}
b30d9d
 
b30d9d
@@ -776,7 +776,7 @@
b30d9d
 			EPRINT((env, DB_STR_A("1116",
b30d9d
 			    "Page %lu: hash page referenced twice", "%lu"),
b30d9d
 			    (u_long)pgno));
b30d9d
+			ret = DB_VERIFY_FATAL;
b30d9d
-			isbad = 1;
b30d9d
 			/* Unsafe to continue. */
b30d9d
 			goto err;
b30d9d
 		} else if ((ret = __db_vrfy_pgset_inc(vdp->pgset,
b30d9d
@@ -1307,7 +1307,11 @@
b30d9d
 	COMPQUIET(flags, 0);
b30d9d
 	ip = vdp->thread_info;
b30d9d
 
b30d9d
+	if (pgset == NULL) {
b30d9d
+		EPRINT((dbp->env, DB_STR("5548",
b30d9d
+			"Error, database contains no visible pages.")));
b30d9d
+		return (DB_VERIFY_FATAL);
b30d9d
+	}
b30d9d
-	DB_ASSERT(dbp->env, pgset != NULL);
b30d9d
 
b30d9d
 	mpf = dbp->mpf;
b30d9d
 	totpgs = 0;
b30d9d
--- db-18.1.32/src/qam/qam_verify.c	2019-02-20 03:21:20.000000000 +0530
b30d9d
+++ db-18.1.40/src/qam/qam_verify.c	2020-05-29 23:28:22.000000000 +0530
b30d9d
@@ -465,7 +465,14 @@
b30d9d
 	/* Verify/salvage each page. */
b30d9d
 	if ((ret = __db_cursor(dbp, vdp->thread_info, NULL, &dbc, 0)) != 0)
b30d9d
 		return (ret);
b30d9d
-begin:	for (; i <= stop; i++) {
b30d9d
+begin:	if ((stop - i) > 100000) {
b30d9d
+		EPRINT((env, DB_STR_A("5551",
b30d9d
+"Warning, many possible extends files (%lu), will take a long time to verify",
b30d9d
+          "%lu"), (u_long)(stop - i)));
b30d9d
+	}
b30d9d
+	for (; i <= stop; i++) {
b30d9d
+		if (i == UINT32_MAX)
b30d9d
+			break;
b30d9d
 		/*
b30d9d
 		 * If DB_SALVAGE is set, we inspect our database of completed
b30d9d
 		 * pages, and skip any we've already printed in the subdb pass.