summaryrefslogtreecommitdiffstats
path: root/lib/libc/db/hash/hash_page.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2009-03-28 06:30:43 +0000
committerdelphij <delphij@FreeBSD.org>2009-03-28 06:30:43 +0000
commitbe23f69f403b512b59926d78baae02cd2fb18778 (patch)
treef5ce199c5fb18974683a6436371f31ef3dd61245 /lib/libc/db/hash/hash_page.c
parent7a713ce8b411c402e521967c5c26f028adfb6a99 (diff)
downloadFreeBSD-src-be23f69f403b512b59926d78baae02cd2fb18778.zip
FreeBSD-src-be23f69f403b512b59926d78baae02cd2fb18778.tar.gz
Fix a crash when iterating over a hash and removing its elements.
Obtained from: OpenBSD
Diffstat (limited to 'lib/libc/db/hash/hash_page.c')
-rw-r--r--lib/libc/db/hash/hash_page.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c
index e34b30f..f1cde8f 100644
--- a/lib/libc/db/hash/hash_page.c
+++ b/lib/libc/db/hash/hash_page.c
@@ -155,6 +155,14 @@ __delpair(HTAB *hashp, BUFHEAD *bufp, int ndx)
bp[i - 1] = bp[i + 1] + pairlen;
}
}
+ if (ndx == hashp->cndx) {
+ /*
+ * We just removed pair we were "pointing" to.
+ * By moving back the cndx we ensure subsequent
+ * hash_seq() calls won't skip over any entries.
+ */
+ hashp->cndx -= 2;
+ }
}
/* Finally adjust the page data */
bp[n] = OFFSET(bp) + pairlen;
OpenPOWER on IntegriCloud