Blame SOURCES/db-5.3.28_cve-2019-2708.patch

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