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

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