1 --- db-18.1.32/src/btree/bt_cursor.c 2019-02-20 03:21:20.000000000 +0530
2 +++ db-18.1.40/src/btree/bt_cursor.c 2020-05-29 23:28:22.000000000 +0530
5 * Recno uses the btree bt_ovflsize value -- it's close enough.
7 + if (t->bt_minkey == 0)
9 cp->ovflsize = B_MINKEY_TO_OVFLSIZE(
10 dbp, F_ISSET(dbc, DBC_OPD) ? 2 : t->bt_minkey, dbp->pgsize);
12 --- db-18.1.32/src/btree/bt_verify.c 2019-02-20 03:21:20.000000000 +0530
13 +++ db-18.1.40/src/btree/bt_verify.c 2020-05-29 23:28:22.000000000 +0530
20 + ret = DB_VERIFY_FATAL;
23 - DB_ASSERT(env, ret != 0);
28 DBT dbta, dbtb, dup_1, dup_2, *p1, *p2, *tmp;
31 + db_pgno_t cpgno, grandparent;
35 int adj, cmp, freedup_1, freedup_2, isbad, ret, t_ret;
40 + if (LF_ISSET(DB_NOORDERCHK))
42 - DB_ASSERT(env, !LF_ISSET(DB_NOORDERCHK));
44 dupfunc = (dbp->dup_compare == NULL) ? __bam_defcmp : dbp->dup_compare;
45 if (TYPE(h) == P_LDUP)
48 if (dbp->bt_internal != NULL) {
49 bt = (BTREE *)dbp->bt_internal;
50 + grandparent = bt->bt_root;
51 if (TYPE(h) == P_IBTREE && (bt->bt_compare != NULL ||
52 dupfunc != __bam_defcmp)) {
59 while (TYPE(child) == P_IBTREE) {
60 + if (NUM_ENT(child) == 0) {
61 + EPRINT((env, DB_STR_A("1088",
62 + "Page %lu: internal page is empty and should not be",
63 + "%lu"), (u_long)cpgno));
64 + ret = DB_VERIFY_BAD;
67 bi = GET_BINTERNAL(dbp, child, 0);
68 + if (grandparent == bi->pgno) {
69 + EPRINT((env, DB_STR_A("5552",
70 + "Page %lu: found twice in the btree",
71 + "%lu"), (u_long)grandparent));
72 + ret = DB_VERIFY_FATAL;
75 + grandparent = cpgno;
78 (ret = __memp_fput(mpf,
79 @@ -1402,7 +1416,10 @@
81 if (dup_1.data == NULL ||
87 - DB_ASSERT(env, !ovflok);
91 @@ -1747,9 +1764,10 @@
92 (ret = __db_vrfy_ovfl_structure(dbp, vdp,
93 child->pgno, child->tlen,
94 flags | DB_ST_OVFL_LEAF)) != 0) {
95 + if (ret == DB_VERIFY_BAD) {
96 - if (ret == DB_VERIFY_BAD)
104 @@ -1823,9 +1841,10 @@
105 stflags | DB_ST_TOPLEVEL,
106 NULL, NULL, NULL)) != 0) {
117 @@ -1969,7 +1988,10 @@
120 /* Otherwise, __db_vrfy_childput would be broken. */
121 + if (child->refcnt < 1) {
125 - DB_ASSERT(env, child->refcnt >= 1);
128 * An overflow referenced more than twice here
129 @@ -1986,9 +2008,10 @@
130 if ((ret = __db_vrfy_ovfl_structure(dbp,
131 vdp, child->pgno, child->tlen,
133 + if (ret == DB_VERIFY_BAD) {
134 - if (ret == DB_VERIFY_BAD)
142 @@ -2026,9 +2049,10 @@
143 if ((ret = __bam_vrfy_subtree(dbp, vdp, li->pgno,
144 i == 0 ? NULL : li, ri, flags, &child_level,
145 &child_nrecs, NULL)) != 0) {
146 + if (ret == DB_VERIFY_BAD) {
147 - if (ret == DB_VERIFY_BAD)
155 @@ -2929,7 +2953,11 @@
156 db_pgno_t current, p;
159 + if (pgset == NULL) {
160 + EPRINT((dbp->env, DB_STR("5542",
161 + "Error, database contains no visible pages.")));
162 + return (DB_RUNRECOVERY);
164 - DB_ASSERT(dbp->env, pgset != NULL);
168 --- db-18.1.32/src/db/db_conv.c 2019-02-20 03:21:20.000000000 +0530
169 +++ db-18.1.40/src/db/db_conv.c 2020-05-29 23:28:22.000000000 +0530
171 db_indx_t i, *inp, len, tmp;
172 u_int8_t *end, *p, *pgend;
176 + /* This function is also used to byteswap logs, so
177 + * the pagesize might not be an actual page size.
179 + if (!(pagesize >= 24 && pagesize <= DB_MAX_PGSIZE))
183 M_32_SWAP(h->lsn.file);
184 @@ -513,26 +516,41 @@
185 pgend = (u_int8_t *)h + pagesize;
188 - if ((u_int8_t *)inp >= pgend)
190 + if ((u_int8_t *)inp > pgend)
191 + return (__db_pgfmt(env, pg));
194 case P_HASH_UNSORTED:
196 for (i = 0; i < NUM_ENT(h); i++) {
197 + if ((u_int8_t*)(inp + i) >= pgend)
198 + return (__db_pgfmt(env, pg));
203 + if (inp[i] >= pagesize)
204 + return (__db_pgfmt(env, pg));
206 - if (P_ENTRY(dbp, h, i) >= pgend)
208 + if (P_ENTRY(dbp, h, i) >= pgend)
209 + return (__db_pgfmt(env, pg));
211 switch (HPAGE_TYPE(dbp, h, i)) {
215 + if (LEN_HITEM(dbp, h, pagesize, i) <
217 + return (__db_pgfmt(env, pg));
219 len = LEN_HKEYDATA(dbp, h, pagesize, i);
220 p = HKEYDATA_DATA(P_ENTRY(dbp, h, i));
221 - for (end = p + len; p < end;) {
225 + return (__db_pgfmt(env, pg));
231 @@ -544,14 +562,20 @@
236 + return (__db_pgfmt(env, pg));
241 + if ((inp[i] + HOFFDUP_SIZE) > pagesize)
242 + return (__db_pgfmt(env, pg));
243 p = HOFFPAGE_PGNO(P_ENTRY(dbp, h, i));
244 SWAP32(p); /* pgno */
247 + if ((inp[i] + HOFFPAGE_SIZE) > pagesize)
248 + return (__db_pgfmt(env, pg));
249 p = HOFFPAGE_PGNO(P_ENTRY(dbp, h, i));
250 SWAP32(p); /* pgno */
251 SWAP32(p); /* tlen */
254 return (__db_pgfmt(env, pg));
263 for (i = 0; i < NUM_ENT(h); i++) {
264 + if ((u_int8_t *)(inp + i) >= pgend)
265 + return (__db_pgfmt(env, pg));
268 + if (inp[i] >= pagesize)
269 + return (__db_pgfmt(env, pg));
272 * In the case of on-page duplicates, key information
275 bk = GET_BKEYDATA(dbp, h, i);
276 if ((u_int8_t *)bk >= pgend)
278 + return (__db_pgfmt(env, pg));
279 switch (B_TYPE(bk->type)) {
285 bo = (BOVERFLOW *)bk;
286 + if (((u_int8_t *)bo + BOVERFLOW_SIZE) > pgend)
287 + return (__db_pgfmt(env, pg));
291 @@ -618,12 +647,17 @@
294 for (i = 0; i < NUM_ENT(h); i++) {
295 + if ((u_int8_t *)(inp + i) > pgend)
296 + return (__db_pgfmt(env, pg));
299 + if ((u_int16_t)(inp[i] +
300 + BINTERNAL_SIZE(0) - 1) > pagesize)
303 bi = GET_BINTERNAL(dbp, h, i);
304 - if ((u_int8_t *)bi >= pgend)
306 + if (((u_int8_t *)bi + BINTERNAL_SIZE(0)) > pgend)
307 + return (__db_pgfmt(env, pg));
315 + if ((u_int16_t)(inp[i] +
316 + BINTERNAL_SIZE(BOVERFLOW_SIZE) - 1) >
319 bo = (BOVERFLOW *)bi->data;
322 @@ -648,12 +686,16 @@
325 for (i = 0; i < NUM_ENT(h); i++) {
326 + if ((u_int8_t *)(inp + i) >= pgend)
327 + return (__db_pgfmt(env, pg));
330 + if (inp[i] >= pagesize)
331 + return (__db_pgfmt(env, pg));
333 ri = GET_RINTERNAL(dbp, h, i);
334 - if ((u_int8_t *)ri >= pgend)
336 + if ((((u_int8_t *)ri) + RINTERNAL_SIZE) > pgend)
337 + return (__db_pgfmt(env, pg));
340 M_32_SWAP(ri->nrecs);
341 --- db-18.1.32/src/db/db_vrfy.c 2019-02-20 03:21:20.000000000 +0530
342 +++ db-18.1.40/src/db/db_vrfy.c 2020-05-29 23:28:22.000000000 +0530
344 vdp, name, 0, lp, rp, flags)) != 0) {
345 if (t_ret == DB_VERIFY_BAD)
358 if ((t_ret = __memp_fget(mpf, &i,
359 vdp->thread_info, NULL, 0, &h)) != 0) {
360 + if ((dbp->type == DB_HASH ||
361 - if (dbp->type == DB_HASH ||
362 (dbp->type == DB_QUEUE &&
363 + F_ISSET(dbp, DB_AM_INMEM))) &&
364 + t_ret != DB_RUNRECOVERY) {
365 - F_ISSET(dbp, DB_AM_INMEM))) {
367 __db_vrfy_getpageinfo(vdp, i, &pip)) != 0)
370 return (ret == 0 ? t_ret : ret);
373 + if (ret == DB_PAGE_NOTFOUND && isbad == 1)
375 return ((isbad == 1 && ret == 0) ? DB_VERIFY_BAD : ret);
378 @@ -1581,7 +1586,7 @@
379 if (pgno == PGNO_BASE_MD &&
380 dbtype != DB_QUEUE && meta->last_pgno != vdp->last_pgno) {
381 #ifdef HAVE_FTRUNCATE
382 + ret = DB_VERIFY_FATAL;
384 EPRINT((env, DB_STR_A("0552",
385 "Page %lu: last_pgno is not correct: %lu != %lu",
386 "%lu %lu %lu"), (u_long)pgno,
387 @@ -1622,7 +1627,11 @@
391 + if (pgset == NULL) {
392 + EPRINT((env, DB_STR("5543",
393 + "Error, database contains no visible pages.")));
394 + return (DB_RUNRECOVERY);
396 - DB_ASSERT(env, pgset != NULL);
398 if ((ret = __db_vrfy_getpageinfo(vdp, meta, &pip)) != 0)
400 @@ -2014,7 +2023,8 @@
401 int keyflag, ret, t_ret;
404 + if (!LF_ISSET(DB_SALVAGE))
406 - DB_ASSERT(env, LF_ISSET(DB_SALVAGE));
410 @@ -2126,10 +2136,8 @@
411 int (*callback) __P((void *, const void *));
417 - DB_ASSERT(env, LF_ISSET(DB_SALVAGE));
418 + if (!LF_ISSET(DB_SALVAGE))
421 /* If we got this page in the subdb pass, we can safely skip it. */
422 if (__db_salvage_isdone(vdp, pgno))
423 @@ -2242,8 +2253,8 @@
426 case SALVAGE_OVERFLOW:
427 + EPRINT((env, DB_STR("5544", "Invalid page type to salvage.")));
429 - DB_ASSERT(env, 0); /* Shouldn't ever happen. */
432 if ((t_ret = __ham_salvage(dbp, vdp,
433 pgno, h, handle, callback, flags)) != 0 && ret == 0)
434 @@ -2256,8 +2267,8 @@
435 * Shouldn't happen, but if it does, just do what the
438 + EPRINT((env, DB_STR("5545", "Invalid page type to salvage.")));
443 if ((t_ret = __memp_fput(mpf,
444 vdp->thread_info, h, dbp->priority)) != 0 && ret == 0)
445 @@ -2303,8 +2314,8 @@
449 + EPRINT((env, DB_STR("5546", "Invalid page type to salvage.")));
451 - DB_ASSERT(env, 0); /* Shouldn't ever happen. */
454 if ((t_ret = __memp_fput(mpf,
455 vdp->thread_info, h, dbp->priority)) != 0 && ret == 0)
456 @@ -2361,7 +2372,10 @@
460 + if (himarkp == NULL) {
461 + __db_msg(env, "Page %lu index has no end.", (u_long)pgno);
462 + return (DB_VERIFY_FATAL);
464 - DB_ASSERT(env, himarkp != NULL);
468 @@ -2783,7 +2797,11 @@
470 ovfl_bufsz = bkkey->len + 1;
472 + if (subdbname == NULL) {
473 + EPRINT((env, DB_STR("5547", "Subdatabase cannot be null.")));
477 - DB_ASSERT(env, subdbname != NULL);
478 memcpy(subdbname, bkkey->data, bkkey->len);
479 subdbname[bkkey->len] = '\0';
481 --- db-18.1.32/src/db/db_vrfyutil.c 2019-02-20 03:21:20.000000000 +0530
482 +++ db-18.1.40/src/db/db_vrfyutil.c 2020-05-29 23:28:22.000000000 +0530
484 if ((ret = __db_get(pgdbp,
485 vdp->thread_info, vdp->txn, &key, &data, 0)) == 0) {
487 + if (data.size != sizeof(VRFY_PAGEINFO))
488 + return (DB_VERIFY_FATAL);
489 - DB_ASSERT(env, data.size == sizeof(VRFY_PAGEINFO));
491 LIST_INSERT_HEAD(&vdp->activepips, pip, links);
494 F_SET(&data, DB_DBT_USERMEM);
496 if ((ret = __db_get(dbp, ip, txn, &key, &data, 0)) == 0) {
497 + if (data.size != sizeof(int))
499 - DB_ASSERT(dbp->env, data.size == sizeof(int));
500 } else if (ret == DB_NOTFOUND)
504 F_SET(&data, DB_DBT_USERMEM);
506 if ((ret = __db_get(dbp, ip, txn, &key, &data, 0)) == 0) {
507 + if (data.size != sizeof(int))
508 + return (DB_VERIFY_FATAL);
509 - DB_ASSERT(dbp->env, data.size == sizeof(int));
510 } else if (ret != DB_NOTFOUND)
514 if ((ret = __dbc_get(dbc, &key, &data, DB_NEXT)) != 0)
517 + if (key.size != sizeof(db_pgno_t))
518 + return (DB_VERIFY_FATAL);
519 - DB_ASSERT(dbc->env, key.size == sizeof(db_pgno_t));
524 if ((ret = __dbc_get(dbc, &key, &data, DB_SET)) != 0)
527 + if (data.size != sizeof(VRFY_CHILDINFO))
528 + return (DB_VERIFY_FATAL);
529 - DB_ASSERT(dbc->env, data.size == sizeof(VRFY_CHILDINFO));
530 *cipp = (VRFY_CHILDINFO *)data.data;
534 if ((ret = __dbc_get(dbc, &key, &data, DB_NEXT_DUP)) != 0)
537 + if (data.size != sizeof(VRFY_CHILDINFO))
538 + return (DB_VERIFY_FATAL);
539 - DB_ASSERT(dbc->env, data.size == sizeof(VRFY_CHILDINFO));
540 *cipp = (VRFY_CHILDINFO *)data.data;
546 while ((ret = __dbc_get(*dbcp, &key, &data, DB_NEXT)) == 0) {
547 + if (data.size != sizeof(u_int32_t))
548 + return (DB_VERIFY_FATAL);
549 - DB_ASSERT(dbp->env, data.size == sizeof(u_int32_t));
550 memcpy(&pgtype, data.data, sizeof(pgtype));
552 if (skip_overflow && pgtype == SALVAGE_OVERFLOW)
554 if ((ret = __dbc_del(*dbcp, 0)) != 0)
556 if (pgtype != SALVAGE_IGNORE) {
557 + if (key.size != sizeof(db_pgno_t)
558 + || data.size != sizeof(u_int32_t))
559 + return (DB_VERIFY_FATAL);
560 - DB_ASSERT(dbp->env, key.size == sizeof(db_pgno_t));
561 - DB_ASSERT(dbp->env, data.size == sizeof(u_int32_t));
563 *pgnop = *(db_pgno_t *)key.data;
564 *pgtypep = *(u_int32_t *)data.data;
565 --- db-18.1.32/src/db/partition.c 2019-02-20 03:21:20.000000000 +0530
566 +++ db-18.1.40/src/db/partition.c 2020-05-29 23:28:22.000000000 +0530
569 part->nparts = meta->nparts;
570 } else if (meta->nparts != 0 && part->nparts != meta->nparts) {
572 __db_errx(env, DB_STR("0656",
573 "Number of partitions does not match."));
578 + * There is no limit on the number of partitions, but I cannot imagine a real
579 + * database having more than 10000.
581 + if (meta->nparts > 10000) {
583 + __db_errx(env, DB_STR_A("5553",
584 + "Too many partitions %lu", "%lu"), (u_long)(meta->nparts));
588 @@ -2106,10 +2116,13 @@
589 memcpy(rp->data, key->data, key->size);
590 B_TSET(rp->type, B_KEYDATA);
592 +vrfy: if ((t_ret = __db_verify(*pdbp, ip, (*pdbp)->fname,
593 + NULL, handle, callback,
594 + lp, rp, flags | DB_VERIFY_PARTITION)) != 0 && ret == 0) {
599 -vrfy: if ((t_ret = __db_verify(*pdbp, ip, (*pdbp)->fname,
600 - NULL, handle, callback,
601 - lp, rp, flags | DB_VERIFY_PARTITION)) != 0 && ret == 0)
606 --- db-18.1.32/src/hash/hash_page.c 2019-02-20 03:21:20.000000000 +0530
607 +++ db-18.1.40/src/hash/hash_page.c 2020-05-29 23:28:22.000000000 +0530
609 /* Validate that next, prev pointers are OK */
613 + __db_errx(dbp->env, DB_STR_A("5549",
614 + "Odd number of entries on page: %lu", "%lu"), (u_long)(p->pgno));
615 + return (DB_VERIFY_FATAL);
617 - DB_ASSERT(dbp->env, n%2 == 0 );
622 if ((ret = __db_prpage(dbp, p, DB_PR_PAGE)) != 0)
626 + __db_errx(env, DB_STR_A("5550",
627 + "Odd number of entries on page: %lu", "%lu"),
629 + return (DB_VERIFY_FATAL);
631 - DB_ASSERT(dbp->env, res < 0);
635 --- db-18.1.32/src/hash/hash_verify.c 2019-02-20 03:21:20.000000000 +0530
636 +++ db-18.1.40/src/hash/hash_verify.c 2020-05-29 23:28:22.000000000 +0530
645 * There may be unused hash pages corresponding to buckets
647 "Page %lu: impossible first page in bucket %lu", "%lu %lu"),
648 (u_long)pgno, (u_long)bucket));
649 /* Unsafe to continue. */
650 + ret = DB_VERIFY_FATAL;
656 EPRINT((env, DB_STR_A("1116",
657 "Page %lu: hash page referenced twice", "%lu"),
659 + ret = DB_VERIFY_FATAL;
661 /* Unsafe to continue. */
663 } else if ((ret = __db_vrfy_pgset_inc(vdp->pgset,
664 @@ -1307,7 +1307,11 @@
666 ip = vdp->thread_info;
668 + if (pgset == NULL) {
669 + EPRINT((dbp->env, DB_STR("5548",
670 + "Error, database contains no visible pages.")));
671 + return (DB_VERIFY_FATAL);
673 - DB_ASSERT(dbp->env, pgset != NULL);
677 --- db-18.1.32/src/qam/qam_verify.c 2019-02-20 03:21:20.000000000 +0530
678 +++ db-18.1.40/src/qam/qam_verify.c 2020-05-29 23:28:22.000000000 +0530
680 /* Verify/salvage each page. */
681 if ((ret = __db_cursor(dbp, vdp->thread_info, NULL, &dbc, 0)) != 0)
683 -begin: for (; i <= stop; i++) {
684 +begin: if ((stop - i) > 100000) {
685 + EPRINT((env, DB_STR_A("5551",
686 +"Warning, many possible extends files (%lu), will take a long time to verify",
687 + "%lu"), (u_long)(stop - i)));
689 + for (; i <= stop; i++) {
690 + if (i == UINT32_MAX)
693 * If DB_SALVAGE is set, we inspect our database of completed
694 * pages, and skip any we've already printed in the subdb pass.