CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: kamil Date: Fri Feb 21 22:04:06 UTC 2020 Modified Files: src/lib/libc/db/hash: hash.h Log Message: Avoid undefined behavior in *BIT macros hash_page.c:792:2, left shift of 1 by 31 places cannot be represented in type 'int' hash_page.c:855:2, left shift of 1 by 31 places cannot be represented in type 'int' hash_page.c:779:3, left shift of 1 by 31 places cannot be represented in type 'int' To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/hash/hash.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash.h diff -u src/lib/libc/db/hash/hash.h:1.16 src/lib/libc/db/hash/hash.h:1.17 --- src/lib/libc/db/hash/hash.h:1.16 Wed Nov 18 18:22:42 2015 +++ src/lib/libc/db/hash/hash.h Fri Feb 21 22:04:06 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.16 2015/11/18 18:22:42 christos Exp $ */ +/* $NetBSD: hash.h,v 1.17 2020/02/21 22:04:06 kamil Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -156,9 +156,9 @@ typedef struct htab { /* Memory reside #define BITS_PER_MAP 32 /* Given the address of the beginning of a big map, clear/set the nth bit */ -#define CLRBIT(A, N) ((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP))) -#define SETBIT(A, N) ((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP))) -#define ISSET(A, N) ((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP))) +#define CLRBIT(A, N) ((A)[(N)/BITS_PER_MAP] &= ~(1U<<((N)%BITS_PER_MAP))) +#define SETBIT(A, N) ((A)[(N)/BITS_PER_MAP] |= (1U<<((N)%BITS_PER_MAP))) +#define ISSET(A, N) ((A)[(N)/BITS_PER_MAP] & (1U<<((N)%BITS_PER_MAP))) /* Overflow management */ /*
CVS commit: src/lib/libc/db/btree
Module Name:src Committed By: joerg Date: Sun Oct 9 11:48:24 UTC 2016 Modified Files: src/lib/libc/db/btree: bt_debug.c Log Message: Fix syntax for currently not compiled in code. From Henning Petersen in PR lib/51538. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/btree/bt_debug.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_debug.c diff -u src/lib/libc/db/btree/bt_debug.c:1.18 src/lib/libc/db/btree/bt_debug.c:1.19 --- src/lib/libc/db/btree/bt_debug.c:1.18 Sat Sep 24 21:31:25 2016 +++ src/lib/libc/db/btree/bt_debug.c Sun Oct 9 11:48:24 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_debug.c,v 1.18 2016/09/24 21:31:25 christos Exp $ */ +/* $NetBSD: bt_debug.c,v 1.19 2016/10/09 11:48:24 joerg Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_debug.c,v 1.18 2016/09/24 21:31:25 christos Exp $"); +__RCSID("$NetBSD: bt_debug.c,v 1.19 2016/10/09 11:48:24 joerg Exp $"); #include #include @@ -312,7 +312,7 @@ __bt_stat(DB *dbp) pcont = pinternal = pleaf = 0; nkeys = ifree = lfree = 0; for (i = P_ROOT; i < t->bt_mp->npages && - (h = mpool_get(t->bt_mp, i, MPOOL_IGNOREPIN)) != NULL; ++i) + (h = mpool_get(t->bt_mp, i, MPOOL_IGNOREPIN)) != NULL; ++i) { switch (h->flags & P_TYPE) { case P_BINTERNAL: case P_RINTERNAL:
CVS commit: src/lib/libc/db
Module Name:src Committed By: christos Date: Sat Sep 24 20:11:12 UTC 2016 Modified Files: src/lib/libc/db/btree: bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_open.c bt_overflow.c bt_page.c bt_put.c bt_search.c bt_seq.c bt_split.c extern.h src/lib/libc/db/mpool: mpool.c src/lib/libc/db/recno: rec_open.c rec_search.c Log Message: Merge the recursive tree traversal changes from the mit kerberos tree. This Also make the tracefile customizable. Unfortunately we can't merge any of the hash changes because they have a different on-disk format. That does not matter really because we've fixed most of the problems... To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/lib/libc/db/btree/bt_close.c cvs rdiff -u -r1.14 -r1.15 src/lib/libc/db/btree/bt_conv.c cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/btree/bt_debug.c cvs rdiff -u -r1.17 -r1.18 src/lib/libc/db/btree/bt_delete.c \ src/lib/libc/db/btree/bt_search.c cvs rdiff -u -r1.27 -r1.28 src/lib/libc/db/btree/bt_open.c cvs rdiff -u -r1.20 -r1.21 src/lib/libc/db/btree/bt_overflow.c \ src/lib/libc/db/btree/bt_put.c src/lib/libc/db/btree/bt_split.c cvs rdiff -u -r1.13 -r1.14 src/lib/libc/db/btree/bt_page.c cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/btree/bt_seq.c cvs rdiff -u -r1.12 -r1.13 src/lib/libc/db/btree/extern.h cvs rdiff -u -r1.21 -r1.22 src/lib/libc/db/mpool/mpool.c cvs rdiff -u -r1.20 -r1.21 src/lib/libc/db/recno/rec_open.c cvs rdiff -u -r1.14 -r1.15 src/lib/libc/db/recno/rec_search.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_close.c diff -u src/lib/libc/db/btree/bt_close.c:1.15 src/lib/libc/db/btree/bt_close.c:1.16 --- src/lib/libc/db/btree/bt_close.c:1.15 Wed Aug 31 02:23:51 2016 +++ src/lib/libc/db/btree/bt_close.c Sat Sep 24 16:11:12 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_close.c,v 1.15 2016/08/31 06:23:51 christos Exp $ */ +/* $NetBSD: bt_close.c,v 1.16 2016/09/24 20:11:12 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_close.c,v 1.15 2016/08/31 06:23:51 christos Exp $"); +__RCSID("$NetBSD: bt_close.c,v 1.16 2016/09/24 20:11:12 christos Exp $"); #include "namespace.h" @@ -164,7 +164,7 @@ bt_meta(BTREE *t) BTMETA m; void *p; - if ((p = mpool_get(t->bt_mp, P_META, 0)) == NULL) + if ((p = mpool_getf(t->bt_mp, P_META, 0)) == NULL) return (RET_ERROR); /* Fill in metadata. */ Index: src/lib/libc/db/btree/bt_conv.c diff -u src/lib/libc/db/btree/bt_conv.c:1.14 src/lib/libc/db/btree/bt_conv.c:1.15 --- src/lib/libc/db/btree/bt_conv.c:1.14 Wed Sep 10 13:52:35 2008 +++ src/lib/libc/db/btree/bt_conv.c Sat Sep 24 16:11:12 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_conv.c,v 1.14 2008/09/10 17:52:35 joerg Exp $ */ +/* $NetBSD: bt_conv.c,v 1.15 2016/09/24 20:11:12 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,10 +37,11 @@ #endif #include -__RCSID("$NetBSD: bt_conv.c,v 1.14 2008/09/10 17:52:35 joerg Exp $"); +__RCSID("$NetBSD: bt_conv.c,v 1.15 2016/09/24 20:11:12 christos Exp $"); #include #include +#include #include #include "btree.h" @@ -64,6 +65,7 @@ __bt_pgin(void *t, pgno_t pg, void *pp) indx_t i, top; uint8_t flags; char *p; + uint32_t ksize; if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) return; @@ -101,6 +103,7 @@ __bt_pgin(void *t, pgno_t pg, void *pp) M_16_SWAP(h->linp[i]); p = (char *)(void *)GETBLEAF(h, i); P_32_SWAP(p); + memcpy(, p, sizeof(ksize)); p += sizeof(uint32_t); P_32_SWAP(p); p += sizeof(uint32_t); @@ -113,7 +116,7 @@ __bt_pgin(void *t, pgno_t pg, void *pp) P_32_SWAP(p); } if (flags & P_BIGDATA) { - p += sizeof(uint32_t); + p += ksize; P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -129,6 +132,7 @@ __bt_pgout(void *t, pgno_t pg, void *pp) indx_t i, top; uint8_t flags; char *p; + uint32_t ksize; if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) return; @@ -157,6 +161,7 @@ __bt_pgout(void *t, pgno_t pg, void *pp) else if ((h->flags & P_TYPE) == P_BLEAF) for (i = 0; i < top; i++) { p = (char *)(void *)GETBLEAF(h, i); + ksize = GETBLEAF(h, i)->ksize; P_32_SWAP(p); p += sizeof(uint32_t); P_32_SWAP(p); @@ -170,7 +175,7 @@ __bt_pgout(void *t, pgno_t pg, void *pp) P_32_SWAP(p); } if (flags & P_BIGDATA) { - p += sizeof(uint32_t); + p += ksize; P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); Index: src/lib/libc/db/btree/bt_debug.c diff -u src/lib/libc/db/btree/bt_debug.c:1.16 src/lib/libc/db/btree/bt_debug.c:1.17 --- src/lib/libc/db/btree/bt_debug.c:1.16 Sun Jul 17 16:47:39 2011 +++ src/lib/libc/db/btree/bt_debug.c Sat Sep 24 16:11:12 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_debug.c,v 1.16 2011/07/17 20:47:39 christos Exp $ */ +/* $NetBSD: bt_debug.c,v 1.17 2016/09/24 20:11:12 christos Exp
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Sat Sep 24 20:08:29 UTC 2016 Modified Files: src/lib/libc/db/hash: hash_page.c Log Message: When writing out pages in the "other endian" format, make a copy instead of trashing the in-memory one. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/lib/libc/db/hash/hash_page.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash_page.c diff -u src/lib/libc/db/hash/hash_page.c:1.28 src/lib/libc/db/hash/hash_page.c:1.29 --- src/lib/libc/db/hash/hash_page.c:1.28 Wed Nov 18 13:22:42 2015 +++ src/lib/libc/db/hash/hash_page.c Sat Sep 24 16:08:29 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_page.c,v 1.28 2015/11/18 18:22:42 christos Exp $ */ +/* $NetBSD: hash_page.c,v 1.29 2016/09/24 20:08:29 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash_page.c,v 1.28 2015/11/18 18:22:42 christos Exp $"); +__RCSID("$NetBSD: hash_page.c,v 1.29 2016/09/24 20:08:29 christos Exp $"); /* * PACKAGE: hashing @@ -593,6 +593,7 @@ __put_page(HTAB *hashp, char *p, uint32_ { int fd, page, size; ssize_t wsize; + char pbuf[MAX_BSIZE]; size = HASH_BSIZE(hashp); if ((hashp->fp == -1) && (hashp->fp = __dbtemp("_hash", NULL)) == -1) @@ -603,15 +604,18 @@ __put_page(HTAB *hashp, char *p, uint32_ int i; int max; + memcpy(pbuf, p, size); if (is_bitmap) { max = (uint32_t)hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) -M_32_SWAP(((int *)(void *)p)[i]); +M_32_SWAP(((int *)(void *)pbuf)[i]); } else { - max = ((uint16_t *)(void *)p)[0] + 2; + uint16_t *bp = (uint16_t *)(void *)pbuf; + max = bp[0] + 2; for (i = 0; i <= max; i++) -M_16_SWAP(((uint16_t *)(void *)p)[i]); +M_16_SWAP(bp[i]); } + p = pbuf; } if (is_bucket) page = BUCKET_TO_PAGE(bucket);
CVS commit: src/lib/libc/db/btree
Module Name:src Committed By: christos Date: Wed Aug 31 06:23:51 UTC 2016 Modified Files: src/lib/libc/db/btree: bt_close.c Log Message: don't shortcut closing if the metadata is dirty (from the krb5 tree) To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/db/btree/bt_close.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_close.c diff -u src/lib/libc/db/btree/bt_close.c:1.14 src/lib/libc/db/btree/bt_close.c:1.15 --- src/lib/libc/db/btree/bt_close.c:1.14 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/btree/bt_close.c Wed Aug 31 02:23:51 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_close.c,v 1.14 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: bt_close.c,v 1.15 2016/08/31 06:23:51 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_close.c,v 1.14 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: bt_close.c,v 1.15 2016/08/31 06:23:51 christos Exp $"); #include "namespace.h" @@ -136,7 +136,8 @@ __bt_sync(const DB *dbp, u_int flags) return (RET_ERROR); } - if (F_ISSET(t, B_INMEM | B_RDONLY) || !F_ISSET(t, B_MODIFIED)) + if (F_ISSET(t, B_INMEM | B_RDONLY) + || !F_ISSET(t, B_MODIFIED | B_METADIRTY)) return (RET_SUCCESS); if (F_ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR)
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Wed Nov 18 18:22:42 UTC 2015 Modified Files: src/lib/libc/db/hash: hash.c hash.h hash_bigkey.c hash_page.c Log Message: Introduce a HASH_BSIZE macro to return the blocksize; in the 64K case this returns 0x to avoid overflow. This is used where sizes are stored. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/lib/libc/db/hash/hash.c cvs rdiff -u -r1.15 -r1.16 src/lib/libc/db/hash/hash.h cvs rdiff -u -r1.24 -r1.25 src/lib/libc/db/hash/hash_bigkey.c cvs rdiff -u -r1.27 -r1.28 src/lib/libc/db/hash/hash_page.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash.c diff -u src/lib/libc/db/hash/hash.c:1.37 src/lib/libc/db/hash/hash.c:1.38 --- src/lib/libc/db/hash/hash.c:1.37 Wed Nov 18 08:00:46 2015 +++ src/lib/libc/db/hash/hash.c Wed Nov 18 13:22:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.37 2015/11/18 13:00:46 christos Exp $ */ +/* $NetBSD: hash.c,v 1.38 2015/11/18 18:22:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash.c,v 1.37 2015/11/18 13:00:46 christos Exp $"); +__RCSID("$NetBSD: hash.c,v 1.38 2015/11/18 18:22:42 christos Exp $"); #include "namespace.h" #include @@ -585,7 +585,7 @@ hash_access(HTAB *hashp, ACTION action, hash_accesses++; #endif - off = hashp->BSIZE == MAX_BSIZE ? MAX_BSIZE - 1 : hashp->BSIZE; + off = HASH_BSIZE(hashp); size = key->size; kp = (char *)key->data; rbufp = __get_buf(hashp, __call_hash(hashp, kp, (int)size), NULL, 0); @@ -617,7 +617,7 @@ hash_access(HTAB *hashp, ACTION action, bp = (uint16_t *)(void *)rbufp->page; n = *bp++; ndx = 1; - off = hashp->BSIZE; + off = HASH_BSIZE(hashp); } else if (bp[1] < REAL_KEY) { if ((ndx = __find_bigpair(hashp, rbufp, ndx, kp, (int)size)) > 0) @@ -640,7 +640,7 @@ hash_access(HTAB *hashp, ACTION action, bp = (uint16_t *)(void *)rbufp->page; n = *bp++; ndx = 1; -off = hashp->BSIZE; +off = HASH_BSIZE(hashp); } else { save_bufp->flags &= ~BUF_PIN; return (ERROR); @@ -807,7 +807,7 @@ next_bucket: if (hashp->cpage == NULL) return (ERROR); key->data = (uint8_t *)hashp->cpage->page + bp[ndx]; - key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; + key->size = (ndx > 1 ? bp[ndx - 1] : HASH_BSIZE(hashp)) - bp[ndx]; data->data = (uint8_t *)hashp->cpage->page + bp[ndx + 1]; data->size = bp[ndx] - bp[ndx + 1]; hashp->cndx += 2; Index: src/lib/libc/db/hash/hash.h diff -u src/lib/libc/db/hash/hash.h:1.15 src/lib/libc/db/hash/hash.h:1.16 --- src/lib/libc/db/hash/hash.h:1.15 Tue Aug 26 17:18:38 2008 +++ src/lib/libc/db/hash/hash.h Wed Nov 18 13:22:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.h,v 1.15 2008/08/26 21:18:38 joerg Exp $ */ +/* $NetBSD: hash.h,v 1.16 2015/11/18 18:22:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -123,6 +123,11 @@ typedef struct htab { /* Memory reside * Constants */ #define MAX_BSIZE 65536 /* 2^16 */ +/* + * Make it fit in uint16_t; a better way would be to store size - 1, but + * then we'd need to bump the version. + */ +#define HASH_BSIZE(hp) ((hp)->BSIZE == MAX_BSIZE ? MAX_BSIZE - 1 : (hp)->BSIZE) #define MIN_BUFFERS 6 #define MINHDRSIZE 512 #define DEF_BUFSIZE 65536 /* 64 K */ Index: src/lib/libc/db/hash/hash_bigkey.c diff -u src/lib/libc/db/hash/hash_bigkey.c:1.24 src/lib/libc/db/hash/hash_bigkey.c:1.25 --- src/lib/libc/db/hash/hash_bigkey.c:1.24 Tue Mar 13 17:13:32 2012 +++ src/lib/libc/db/hash/hash_bigkey.c Wed Nov 18 13:22:42 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_bigkey.c,v 1.24 2012/03/13 21:13:32 christos Exp $ */ +/* $NetBSD: hash_bigkey.c,v 1.25 2015/11/18 18:22:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash_bigkey.c,v 1.24 2012/03/13 21:13:32 christos Exp $"); +__RCSID("$NetBSD: hash_bigkey.c,v 1.25 2015/11/18 18:22:42 christos Exp $"); /* * PACKAGE: hash @@ -274,10 +274,10 @@ __big_delete(HTAB *hashp, BUFHEAD *bufp) bufp->ovfl = NULL; n -= 2; bp[0] = n; - temp = hashp->BSIZE - PAGE_META(n); + temp = HASH_BSIZE(hashp) - PAGE_META(n); _DBFIT(temp, uint16_t); FREESPACE(bp) = (uint16_t)temp; - OFFSET(bp) = hashp->BSIZE; + OFFSET(bp) = HASH_BSIZE(hashp); bufp->flags |= BUF_MOD; if (rbufp) @@ -309,9 +309,9 @@ __find_bigpair(HTAB *hashp, BUFHEAD *buf ksize = size; kkey = key; - for (bytes = hashp->BSIZE - bp[ndx]; + for (bytes = HASH_BSIZE(hashp) - bp[ndx]; bytes <= size && bp[ndx + 1] == PARTIAL_KEY; - bytes = hashp->BSIZE - bp[ndx]) { + bytes = HASH_BSIZE(hashp) - bp[ndx]) { if (memcmp(p + bp[ndx], kkey, (size_t)bytes)) return (-2); kkey += bytes; @@ -479,7 +479,7 @@ collect_data(HTAB *hashp, BUFHEAD *bufp, p = bufp->page; bp = (uint16_t *)(void *)p; - mylen
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Wed Nov 18 13:00:46 UTC 2015 Modified Files: src/lib/libc/db/hash: hash.c Log Message: Account for the -1 hack to fit 0x1 in a short in hash_page.c To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/lib/libc/db/hash/hash.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash.c diff -u src/lib/libc/db/hash/hash.c:1.36 src/lib/libc/db/hash/hash.c:1.37 --- src/lib/libc/db/hash/hash.c:1.36 Tue Nov 17 15:19:55 2015 +++ src/lib/libc/db/hash/hash.c Wed Nov 18 08:00:46 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.36 2015/11/17 20:19:55 christos Exp $ */ +/* $NetBSD: hash.c,v 1.37 2015/11/18 13:00:46 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash.c,v 1.36 2015/11/17 20:19:55 christos Exp $"); +__RCSID("$NetBSD: hash.c,v 1.37 2015/11/18 13:00:46 christos Exp $"); #include "namespace.h" #include @@ -585,7 +585,7 @@ hash_access(HTAB *hashp, ACTION action, hash_accesses++; #endif - off = hashp->BSIZE; + off = hashp->BSIZE == MAX_BSIZE ? MAX_BSIZE - 1 : hashp->BSIZE; size = key->size; kp = (char *)key->data; rbufp = __get_buf(hashp, __call_hash(hashp, kp, (int)size), NULL, 0);
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Wed Nov 18 00:23:39 UTC 2015 Modified Files: src/lib/libc/db/hash: hash_page.c Log Message: If MAX_BSIZE == hashp->BSIZE (65536) then it does not fit in a short, and we end up storing 0... This means that every entry needs a page. We store MAX_BSIZE - 1 here, but it would be better to always store (avail - 1) here so that we don't waste a byte and be consistent. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libc/db/hash/hash_page.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash_page.c diff -u src/lib/libc/db/hash/hash_page.c:1.26 src/lib/libc/db/hash/hash_page.c:1.27 --- src/lib/libc/db/hash/hash_page.c:1.26 Sat Nov 30 19:22:48 2013 +++ src/lib/libc/db/hash/hash_page.c Tue Nov 17 19:23:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_page.c,v 1.26 2013/12/01 00:22:48 christos Exp $ */ +/* $NetBSD: hash_page.c,v 1.27 2015/11/18 00:23:39 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash_page.c,v 1.26 2013/12/01 00:22:48 christos Exp $"); +__RCSID("$NetBSD: hash_page.c,v 1.27 2015/11/18 00:23:39 christos Exp $"); /* * PACKAGE: hashing @@ -85,7 +85,9 @@ static int ugly_split(HTAB *, uint32_t, temp = 3 * sizeof(uint16_t); \ _DIAGASSERT((size_t)hashp->BSIZE >= temp); \ ((uint16_t *)(void *)(P))[1] = (uint16_t)(hashp->BSIZE - temp); \ - ((uint16_t *)(void *)(P))[2] = hashp->BSIZE; \ + /* we should be really storing always length - 1 here... */ \ + ((uint16_t *)(void *)(P))[2] = \ + hashp->BSIZE == MAX_BSIZE ? MAX_BSIZE - 1 : hashp->BSIZE; \ } /*
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Tue Nov 17 20:19:55 UTC 2015 Modified Files: src/lib/libc/db/hash: hash.c Log Message: PR/50441: Manuel Bouyer: hash seq enumeration skips keys on big data. XXX: pullup-7 To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/lib/libc/db/hash/hash.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash.c diff -u src/lib/libc/db/hash/hash.c:1.35 src/lib/libc/db/hash/hash.c:1.36 --- src/lib/libc/db/hash/hash.c:1.35 Mon Jun 22 17:16:02 2015 +++ src/lib/libc/db/hash/hash.c Tue Nov 17 15:19:55 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.35 2015/06/22 21:16:02 christos Exp $ */ +/* $NetBSD: hash.c,v 1.36 2015/11/17 20:19:55 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash.c,v 1.35 2015/06/22 21:16:02 christos Exp $"); +__RCSID("$NetBSD: hash.c,v 1.36 2015/11/17 20:19:55 christos Exp $"); #include "namespace.h" #include @@ -770,7 +770,7 @@ next_bucket: hashp->cndx = 1; } } else { - bp = (uint16_t *)(void *)hashp->cpage->page; + bp = (uint16_t *)(void *)bufp->page; if (flag == R_NEXT || flag == 0) { if (hashp->cndx > bp[0]) { hashp->cpage = NULL; @@ -802,6 +802,7 @@ next_bucket: if (bp[ndx + 1] < REAL_KEY) { if (__big_keydata(hashp, bufp, key, data, 1)) return (ERROR); + hashp->cndx = 1; } else { if (hashp->cpage == NULL) return (ERROR); @@ -809,8 +810,8 @@ next_bucket: key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; data->data = (uint8_t *)hashp->cpage->page + bp[ndx + 1]; data->size = bp[ndx] - bp[ndx + 1]; + hashp->cndx += 2; } - hashp->cndx += 2; return (SUCCESS); }
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Mon Jun 22 21:16:02 UTC 2015 Modified Files: src/lib/libc/db/hash: hash.c Log Message: Fix hash iteration that deletes the current element under the cursor by adjusting the position of the iterator appropriately. XXX: pullup 7 To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/lib/libc/db/hash/hash.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash.c diff -u src/lib/libc/db/hash/hash.c:1.34 src/lib/libc/db/hash/hash.c:1.35 --- src/lib/libc/db/hash/hash.c:1.34 Mon Jun 22 14:50:06 2015 +++ src/lib/libc/db/hash/hash.c Mon Jun 22 17:16:02 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.34 2015/06/22 18:50:06 christos Exp $ */ +/* $NetBSD: hash.c,v 1.35 2015/06/22 21:16:02 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: hash.c,v 1.34 2015/06/22 18:50:06 christos Exp $); +__RCSID($NetBSD: hash.c,v 1.35 2015/06/22 21:16:02 christos Exp $); #include namespace.h #include sys/param.h @@ -690,6 +690,27 @@ found: case HASH_DELETE: if (__delpair(hashp, rbufp, ndx)) return (ERROR); + /* + * Our index lags 2 behind on the same page when we are + * deleting the element pointed to by the index; otherwise + * deleting randomly from an iterated hash produces undefined + * results. + */ + if (ndx != hashp-cndx - 2 || rbufp != hashp-cpage) + break; + + if (hashp-cndx 1) { + /* Move back one element */ + hashp-cndx -= 2; + } else { + /* + * Move back one page, and indicate to go to the last + * element of the previous page by setting cndx to -1 + */ + hashp-cbucket--; + hashp-cpage = NULL; + hashp-cndx = -1; + } break; default: abort(); @@ -725,7 +746,7 @@ next_bucket: if (!(bufp = hashp-cpage)) { for (bucket = hashp-cbucket; bucket = (uint32_t)hashp-MAX_BUCKET; - bucket++, hashp-cndx = 1) { + bucket++) { bufp = __get_buf(hashp, bucket, NULL, 0); if (!bufp) return (ERROR); @@ -739,10 +760,18 @@ next_bucket: hashp-cbucket = -1; return (ABNORMAL); } + if (hashp-cndx == -1) { +/* move to the last element of the page */ +hashp-cndx = 1; +while (bp[hashp-cndx - 1] != 0) + hashp-cndx += 2; + } else { +/* start on the first element */ +hashp-cndx = 1; + } } else { bp = (uint16_t *)(void *)hashp-cpage-page; if (flag == R_NEXT || flag == 0) { -hashp-cndx += 2; if (hashp-cndx bp[0]) { hashp-cpage = NULL; hashp-cbucket++; @@ -781,6 +810,7 @@ next_bucket: data-data = (uint8_t *)hashp-cpage-page + bp[ndx + 1]; data-size = bp[ndx] - bp[ndx + 1]; } + hashp-cndx += 2; return (SUCCESS); }
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Mon Jun 22 18:50:06 UTC 2015 Modified Files: src/lib/libc/db/hash: hash.c Log Message: Delay moving to the next key until the next iteration. This avoids returning invalid data to the user if the user deletes the current key, but it also fails to iterate over some keys as will be shown by a unit test. From FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/lib/libc/db/hash/hash.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash.c diff -u src/lib/libc/db/hash/hash.c:1.33 src/lib/libc/db/hash/hash.c:1.34 --- src/lib/libc/db/hash/hash.c:1.33 Sat Nov 30 19:22:48 2013 +++ src/lib/libc/db/hash/hash.c Mon Jun 22 14:50:06 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.33 2013/12/01 00:22:48 christos Exp $ */ +/* $NetBSD: hash.c,v 1.34 2015/06/22 18:50:06 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: hash.c,v 1.33 2013/12/01 00:22:48 christos Exp $); +__RCSID($NetBSD: hash.c,v 1.34 2015/06/22 18:50:06 christos Exp $); #include namespace.h #include sys/param.h @@ -720,6 +720,7 @@ hash_seq(const DB *dbp, DBT *key, DBT *d hashp-cpage = NULL; } +next_bucket: for (bp = NULL; !bp || !bp[0]; ) { if (!(bufp = hashp-cpage)) { for (bucket = hashp-cbucket; @@ -738,8 +739,19 @@ hash_seq(const DB *dbp, DBT *key, DBT *d hashp-cbucket = -1; return (ABNORMAL); } - } else + } else { bp = (uint16_t *)(void *)hashp-cpage-page; + if (flag == R_NEXT || flag == 0) { +hashp-cndx += 2; +if (hashp-cndx bp[0]) { + hashp-cpage = NULL; + hashp-cbucket++; + hashp-cndx = 1; + goto next_bucket; +} + } + } + _DIAGASSERT(bp != NULL); _DIAGASSERT(bufp != NULL); @@ -768,13 +780,6 @@ hash_seq(const DB *dbp, DBT *key, DBT *d key-size = (ndx 1 ? bp[ndx - 1] : hashp-BSIZE) - bp[ndx]; data-data = (uint8_t *)hashp-cpage-page + bp[ndx + 1]; data-size = bp[ndx] - bp[ndx + 1]; - ndx += 2; - if (ndx bp[0]) { - hashp-cpage = NULL; - hashp-cbucket++; - hashp-cndx = 1; - } else - hashp-cndx = ndx; } return (SUCCESS); }
CVS commit: src/lib/libc/db/db
Module Name:src Committed By: christos Date: Tue May 19 13:20:52 UTC 2015 Modified Files: src/lib/libc/db/db: db.c Log Message: Fix the build for ancient (rhel5) systems that don't have O_CLOEXEC XXX: pullup-7 To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/db/db/db.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/db/db.c diff -u src/lib/libc/db/db/db.c:1.17 src/lib/libc/db/db/db.c:1.18 --- src/lib/libc/db/db/db.c:1.17 Mon Dec 22 12:01:42 2014 +++ src/lib/libc/db/db/db.c Tue May 19 09:20:52 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: db.c,v 1.17 2014/12/22 17:01:42 christos Exp $ */ +/* $NetBSD: db.c,v 1.18 2015/05/19 13:20:52 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: db.c,v 1.17 2014/12/22 17:01:42 christos Exp $); +__RCSID($NetBSD: db.c,v 1.18 2015/05/19 13:20:52 christos Exp $); #include namespace.h #include sys/types.h @@ -51,6 +51,10 @@ static int __dberr(void); __weak_alias(dbopen,_dbopen) #endif +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + DB * dbopen(const char *fname, int flags, mode_t mode, DBTYPE type, const void *openinfo)
CVS commit: src/lib/libc/db/db
Module Name:src Committed By: christos Date: Mon Dec 22 17:01:42 UTC 2014 Modified Files: src/lib/libc/db/db: db.c Log Message: whitelist O_CLOEXEC flag, should fix lastlogin issue. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/db/db.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/db/db.c diff -u src/lib/libc/db/db/db.c:1.16 src/lib/libc/db/db/db.c:1.17 --- src/lib/libc/db/db/db.c:1.16 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/db/db.c Mon Dec 22 12:01:42 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: db.c,v 1.16 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: db.c,v 1.17 2014/12/22 17:01:42 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: db.c,v 1.16 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: db.c,v 1.17 2014/12/22 17:01:42 christos Exp $); #include namespace.h #include sys/types.h @@ -59,7 +59,7 @@ dbopen(const char *fname, int flags, mod #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) #define USE_OPEN_FLAGS \ (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ - O_RDWR | O_SHLOCK | O_TRUNC) + O_RDWR | O_SHLOCK | O_TRUNC | O_CLOEXEC) if ((flags ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) switch (type) {
CVS commit: src/lib/libc/db/recno
Module Name:src Committed By: christos Date: Wed Dec 25 19:42:23 UTC 2013 Modified Files: src/lib/libc/db/recno: rec_get.c Log Message: fix bug in previous change (sz should be the size of the newly allocated buffer). To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/db/recno/rec_get.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/recno/rec_get.c diff -u src/lib/libc/db/recno/rec_get.c:1.17 src/lib/libc/db/recno/rec_get.c:1.18 --- src/lib/libc/db/recno/rec_get.c:1.17 Sat Dec 14 13:04:56 2013 +++ src/lib/libc/db/recno/rec_get.c Wed Dec 25 14:42:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rec_get.c,v 1.17 2013/12/14 18:04:56 christos Exp $ */ +/* $NetBSD: rec_get.c,v 1.18 2013/12/25 19:42:23 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: rec_get.c,v 1.17 2013/12/14 18:04:56 christos Exp $); +__RCSID($NetBSD: rec_get.c,v 1.18 2013/12/25 19:42:23 christos Exp $); #include namespace.h #include sys/types.h @@ -175,7 +175,6 @@ __rec_vpipe(BTREE *t, recno_t top) { DBT data; recno_t nrec; - ptrdiff_t len; size_t sz; int bval, ch; uint8_t *p; @@ -195,13 +194,12 @@ __rec_vpipe(BTREE *t, recno_t top) break; } if (sz == 0) { -void *np; -len = p - (uint8_t *)t-bt_rdata.data; -sz = t-bt_rdata.size + 256; -np = realloc(t-bt_rdata.data, sz); +ptrdiff_t len = p - (uint8_t *)t-bt_rdata.data; +size_t tot = t-bt_rdata.size + (sz = 256); +void *np = realloc(t-bt_rdata.data, tot); if (np == NULL) return (RET_ERROR); -t-bt_rdata.size = sz; +t-bt_rdata.size = tot; t-bt_rdata.data = np; p = (uint8_t *)t-bt_rdata.data + len; }
CVS commit: src/lib/libc/db/mpool
Module Name:src Committed By: christos Date: Sat Dec 14 18:04:00 UTC 2013 Modified Files: src/lib/libc/db/mpool: mpool.c Log Message: knf, reduce pointer gymnastics To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/db/mpool/mpool.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/mpool/mpool.c diff -u src/lib/libc/db/mpool/mpool.c:1.20 src/lib/libc/db/mpool/mpool.c:1.21 --- src/lib/libc/db/mpool/mpool.c:1.20 Fri Nov 22 11:25:51 2013 +++ src/lib/libc/db/mpool/mpool.c Sat Dec 14 13:04:00 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpool.c,v 1.20 2013/11/22 16:25:51 christos Exp $ */ +/* $NetBSD: mpool.c,v 1.21 2013/12/14 18:04:00 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: mpool.c,v 1.20 2013/11/22 16:25:51 christos Exp $); +__RCSID($NetBSD: mpool.c,v 1.21 2013/12/14 18:04:00 christos Exp $); #include namespace.h #include sys/queue.h @@ -84,14 +84,14 @@ mpool_open(void *key, int fd, pgno_t pag * We don't currently handle pipes, although we should. */ if (fstat(fd, sb)) - return (NULL); + return NULL; if (!S_ISREG(sb.st_mode)) { errno = ESPIPE; - return (NULL); + return NULL; } /* Allocate and initialize the MPOOL cookie. */ - if ((mp = (MPOOL *)calloc(1, sizeof(MPOOL))) == NULL) + if ((mp = calloc(1, sizeof(*mp))) == NULL) return (NULL); TAILQ_INIT(mp-lqh); for (entry = 0; entry HASHSIZE; ++entry) @@ -100,7 +100,7 @@ mpool_open(void *key, int fd, pgno_t pag mp-npages = (pgno_t)(sb.st_size / pagesize); mp-pagesize = pagesize; mp-fd = fd; - return (mp); + return mp; } /* @@ -139,14 +139,14 @@ mpool_new( MPOOL *mp, pgno_t *pgnoaddr) * and return. */ if ((bp = mpool_bkt(mp)) == NULL) - return (NULL); + return NULL; *pgnoaddr = bp-pgno = mp-npages++; bp-flags = MPOOL_PINNED; head = mp-hqh[HASHKEY(bp-pgno)]; TAILQ_INSERT_HEAD(head, bp, hq); TAILQ_INSERT_TAIL(mp-lqh, bp, q); - return (bp-page); + return bp-page; } /* @@ -165,7 +165,7 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int /* Check for attempt to retrieve a non-existent page. */ if (pgno = mp-npages) { errno = EINVAL; - return (NULL); + return NULL; } #ifdef STATISTICS @@ -193,12 +193,12 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int /* Return a pinned page. */ bp-flags |= MPOOL_PINNED; - return (bp-page); + return bp-page; } /* Get a page from the cache. */ if ((bp = mpool_bkt(mp)) == NULL) - return (NULL); + return NULL; /* Read in the contents. */ #ifdef STATISTICS @@ -208,7 +208,7 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int if ((nr = pread(mp-fd, bp-page, (size_t)mp-pagesize, off)) != (int)mp-pagesize) { if (nr = 0) errno = EFTYPE; - return (NULL); + return NULL; } /* Set the page number, pin the page. */ @@ -227,7 +227,7 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int if (mp-pgin != NULL) (mp-pgin)(mp-pgcookie, bp-pgno, bp-page); - return (bp-page); + return bp-page; } /* @@ -243,7 +243,7 @@ mpool_put(MPOOL *mp, void *page, u_int f #ifdef STATISTICS ++mp-pageput; #endif - bp = (BKT *)(void *)((char *)page - sizeof(BKT)); + bp = (void *)((intptr_t)page - sizeof(BKT)); #ifdef DEBUG if (!(bp-flags MPOOL_PINNED)) { (void)fprintf(stderr, @@ -274,7 +274,7 @@ mpool_close(MPOOL *mp) /* Free the MPOOL cookie. */ free(mp); - return (RET_SUCCESS); + return RET_SUCCESS; } /* @@ -290,10 +290,10 @@ mpool_sync(MPOOL *mp) TAILQ_FOREACH(bp, mp-lqh, q) if (bp-flags MPOOL_DIRTY mpool_write(mp, bp) == RET_ERROR) - return (RET_ERROR); + return RET_ERROR; /* Sync the file descriptor. */ - return (fsync(mp-fd) ? RET_ERROR : RET_SUCCESS); + return fsync(mp-fd) ? RET_ERROR : RET_SUCCESS; } /* @@ -321,7 +321,7 @@ mpool_bkt(MPOOL *mp) /* Flush if dirty. */ if (bp-flags MPOOL_DIRTY mpool_write(mp, bp) == RET_ERROR) -return (NULL); +return NULL; #ifdef STATISTICS ++mp-pageflush; #endif @@ -337,20 +337,20 @@ mpool_bkt(MPOOL *mp) bp-page = spage; } #endif - return (bp); + return bp; } new: if ((bp = calloc(1, (size_t)(sizeof(BKT) + mp-pagesize))) == NULL) - return (NULL); + return NULL; #ifdef STATISTICS ++mp-pagealloc; #endif #if defined(DEBUG) || defined(PURIFY) (void)memset(bp, 0xff, (size_t)(sizeof(BKT) + mp-pagesize)); #endif - bp-page = (char *)(void *)bp + sizeof(BKT); + bp-page = (void *)((intptr_t)bp + sizeof(BKT)); ++mp-curcache; - return (bp); + return bp; } /* @@ -371,8 +371,9 @@ mpool_write(MPOOL *mp, BKT *bp) (mp-pgout)(mp-pgcookie, bp-pgno, bp-page); off = mp-pagesize * bp-pgno; - if (pwrite(mp-fd, bp-page, (size_t)mp-pagesize, off) != (int)mp-pagesize) - return (RET_ERROR); + if (pwrite(mp-fd, bp-page, (size_t)mp-pagesize, off) != + (ssize_t)mp-pagesize) + return RET_ERROR; /* *
CVS commit: src/lib/libc/db
Module Name:src Committed By: christos Date: Sat Dec 14 18:04:56 UTC 2013 Modified Files: src/lib/libc/db/btree: bt_overflow.c bt_utils.c src/lib/libc/db/recno: rec_get.c rec_put.c rec_utils.c Log Message: It's been many years since realloc(NULL, size) == malloc(size). Also don't destroy pointers on allocation errors so someone can free them later. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/db/btree/bt_overflow.c cvs rdiff -u -r1.15 -r1.16 src/lib/libc/db/btree/bt_utils.c cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/recno/rec_get.c cvs rdiff -u -r1.20 -r1.21 src/lib/libc/db/recno/rec_put.c cvs rdiff -u -r1.13 -r1.14 src/lib/libc/db/recno/rec_utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_overflow.c diff -u src/lib/libc/db/btree/bt_overflow.c:1.19 src/lib/libc/db/btree/bt_overflow.c:1.20 --- src/lib/libc/db/btree/bt_overflow.c:1.19 Sat Nov 30 19:22:48 2013 +++ src/lib/libc/db/btree/bt_overflow.c Sat Dec 14 13:04:56 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_overflow.c,v 1.19 2013/12/01 00:22:48 christos Exp $ */ +/* $NetBSD: bt_overflow.c,v 1.20 2013/12/14 18:04:56 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_overflow.c,v 1.19 2013/12/01 00:22:48 christos Exp $); +__RCSID($NetBSD: bt_overflow.c,v 1.20 2013/12/14 18:04:56 christos Exp $); #include namespace.h #include sys/param.h @@ -97,9 +97,10 @@ __ovfl_get(BTREE *t, void *p, size_t *ss #endif /* Make the buffer bigger as necessary. */ if (*bufsz sz) { - *buf = *buf == NULL ? malloc(sz) : realloc(*buf, sz); - if (*buf == NULL) + void *nbuf = realloc(*buf, sz); + if (nbuf == NULL) return (RET_ERROR); + *buf = nbuf; *bufsz = sz; } Index: src/lib/libc/db/btree/bt_utils.c diff -u src/lib/libc/db/btree/bt_utils.c:1.15 src/lib/libc/db/btree/bt_utils.c:1.16 --- src/lib/libc/db/btree/bt_utils.c:1.15 Sat Nov 30 19:22:48 2013 +++ src/lib/libc/db/btree/bt_utils.c Sat Dec 14 13:04:56 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_utils.c,v 1.15 2013/12/01 00:22:48 christos Exp $ */ +/* $NetBSD: bt_utils.c,v 1.16 2013/12/14 18:04:56 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_utils.c,v 1.15 2013/12/01 00:22:48 christos Exp $); +__RCSID($NetBSD: bt_utils.c,v 1.16 2013/12/14 18:04:56 christos Exp $); #include sys/param.h @@ -88,8 +88,7 @@ __bt_ret(BTREE *t, EPG *e, DBT *key, DBT key-data = rkey-data; } else if (copy || F_ISSET(t, B_DB_LOCK)) { if (bl-ksize rkey-size) { - p = rkey-data == NULL ? - malloc(bl-ksize) : realloc(rkey-data, bl-ksize); + p = realloc(rkey-data, bl-ksize); if (p == NULL) return (RET_ERROR); rkey-data = p; @@ -115,9 +114,7 @@ dataonly: } else if (copy || F_ISSET(t, B_DB_LOCK)) { /* Use +1 in case the first record retrieved is 0 length. */ if (bl-dsize + 1 rdata-size) { - p = rdata-data == NULL ? - malloc(bl-dsize + 1) : - realloc(rdata-data, bl-dsize + 1); + p = realloc(rdata-data, bl-dsize + 1); if (p == NULL) return (RET_ERROR); rdata-data = p; Index: src/lib/libc/db/recno/rec_get.c diff -u src/lib/libc/db/recno/rec_get.c:1.16 src/lib/libc/db/recno/rec_get.c:1.17 --- src/lib/libc/db/recno/rec_get.c:1.16 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/recno/rec_get.c Sat Dec 14 13:04:56 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rec_get.c,v 1.16 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: rec_get.c,v 1.17 2013/12/14 18:04:56 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: rec_get.c,v 1.16 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: rec_get.c,v 1.17 2013/12/14 18:04:56 christos Exp $); #include namespace.h #include sys/types.h @@ -127,11 +127,10 @@ __rec_fpipe(BTREE *t, recno_t top) uint8_t *p; if (t-bt_rdata.size t-bt_reclen) { - t-bt_rdata.data = t-bt_rdata.data == NULL ? - malloc(t-bt_reclen) : - realloc(t-bt_rdata.data, t-bt_reclen); - if (t-bt_rdata.data == NULL) + void *np = realloc(t-bt_rdata.data, t-bt_reclen); + if (np == NULL) return (RET_ERROR); + t-bt_rdata.data = np; t-bt_rdata.size = t-bt_reclen; } data.data = t-bt_rdata.data; @@ -196,13 +195,14 @@ __rec_vpipe(BTREE *t, recno_t top) break; } if (sz == 0) { +void *np; len = p - (uint8_t *)t-bt_rdata.data; -t-bt_rdata.size += (sz = 256); -t-bt_rdata.data = t-bt_rdata.data == NULL ? -malloc(t-bt_rdata.size) : -realloc(t-bt_rdata.data, t-bt_rdata.size); -if (t-bt_rdata.data == NULL) +sz = t-bt_rdata.size + 256; +np = realloc(t-bt_rdata.data, sz); +if (np == NULL) return (RET_ERROR); +t-bt_rdata.size = sz; +t-bt_rdata.data = np; p = (uint8_t
CVS commit: src/lib/libc/db
Module Name:src Committed By: christos Date: Sun Dec 1 00:22:48 UTC 2013 Modified Files: src/lib/libc/db/btree: bt_open.c bt_overflow.c bt_utils.c src/lib/libc/db/db: Makefile.inc src/lib/libc/db/hash: hash.c hash_page.c src/lib/libc/db/recno: rec_open.c rec_put.c rec_utils.c Added Files: src/lib/libc/db/db: dbfile.c Log Message: - centralize opening of regular and temp files to avoid code duplication - don't cast malloc - use malloc sizeof(*var) instead of sizeof(type) To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libc/db/btree/bt_open.c cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/btree/bt_overflow.c cvs rdiff -u -r1.14 -r1.15 src/lib/libc/db/btree/bt_utils.c cvs rdiff -u -r1.4 -r1.5 src/lib/libc/db/db/Makefile.inc cvs rdiff -u -r0 -r1.1 src/lib/libc/db/db/dbfile.c cvs rdiff -u -r1.32 -r1.33 src/lib/libc/db/hash/hash.c cvs rdiff -u -r1.25 -r1.26 src/lib/libc/db/hash/hash_page.c cvs rdiff -u -r1.19 -r1.20 src/lib/libc/db/recno/rec_open.c \ src/lib/libc/db/recno/rec_put.c cvs rdiff -u -r1.12 -r1.13 src/lib/libc/db/recno/rec_utils.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_open.c diff -u src/lib/libc/db/btree/bt_open.c:1.26 src/lib/libc/db/btree/bt_open.c:1.27 --- src/lib/libc/db/btree/bt_open.c:1.26 Tue Mar 13 17:13:32 2012 +++ src/lib/libc/db/btree/bt_open.c Sat Nov 30 19:22:48 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_open.c,v 1.26 2012/03/13 21:13:32 christos Exp $ */ +/* $NetBSD: bt_open.c,v 1.27 2013/12/01 00:22:48 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_open.c,v 1.26 2012/03/13 21:13:32 christos Exp $); +__RCSID($NetBSD: bt_open.c,v 1.27 2013/12/01 00:22:48 christos Exp $); /* * Implementation of btree access method for 4.4BSD. @@ -71,7 +71,6 @@ __RCSID($NetBSD: bt_open.c,v 1.26 2012/ static int byteorder(void); static int nroot(BTREE *); -static int tmp(void); /* * __BT_OPEN -- Open a btree. @@ -161,7 +160,7 @@ __bt_open(const char *fname, int flags, goto einval; /* Allocate and initialize DB and BTREE structures. */ - if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL) + if ((t = malloc(sizeof(*t))) == NULL) goto err; memset(t, 0, sizeof(BTREE)); t-bt_fd = -1; /* Don't close unopened fd on error. */ @@ -171,7 +170,7 @@ __bt_open(const char *fname, int flags, t-bt_pfx = b.prefix; t-bt_rfd = -1; - if ((t-bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL) + if ((t-bt_dbp = dbp = malloc(sizeof(*dbp))) == NULL) goto err; memset(t-bt_dbp, 0, sizeof(DB)); if (t-bt_lorder != machine_lorder) @@ -202,24 +201,17 @@ __bt_open(const char *fname, int flags, default: goto einval; } - - if ((t-bt_fd = open(fname, flags, mode)) == -1) - goto err; - if (fcntl(t-bt_fd, F_SETFD, FD_CLOEXEC) == -1) + if ((t-bt_fd = __dbopen(fname, flags, mode, sb)) == -1) goto err; } else { if ((flags O_ACCMODE) != O_RDWR) goto einval; - if ((t-bt_fd = tmp()) == -1) + if ((t-bt_fd = __dbtemp(bt., sb)) == -1) goto err; F_SET(t, B_INMEM); } - if (fcntl(t-bt_fd, F_SETFD, FD_CLOEXEC) == -1) - goto err; - if (fstat(t-bt_fd, sb)) - goto err; if (sb.st_size) { if ((nr = read(t-bt_fd, m, sizeof(BTMETA))) 0) goto err; @@ -390,37 +382,6 @@ nroot(BTREE *t) } static int -tmp(void) -{ - sigset_t set, oset; - int len; - int fd; - char *envtmp; - char path[PATH_MAX]; - - if (issetugid()) - envtmp = NULL; - else - envtmp = getenv(TMPDIR); - - len = snprintf(path, - sizeof(path), %s/bt.XX, envtmp ? envtmp : _PATH_TMP); - if (len 0 || (size_t)len = sizeof(path)) { - errno = ENAMETOOLONG; - return -1; - } - - (void)sigfillset(set); - (void)sigprocmask(SIG_BLOCK, set, oset); - if ((fd = mkstemp(path)) != -1) { - (void)unlink(path); - (void)fcntl(fd, F_SETFD, FD_CLOEXEC); - } - (void)sigprocmask(SIG_SETMASK, oset, NULL); - return(fd); -} - -static int byteorder(void) { uint32_t x; Index: src/lib/libc/db/btree/bt_overflow.c diff -u src/lib/libc/db/btree/bt_overflow.c:1.18 src/lib/libc/db/btree/bt_overflow.c:1.19 --- src/lib/libc/db/btree/bt_overflow.c:1.18 Tue Mar 13 17:13:32 2012 +++ src/lib/libc/db/btree/bt_overflow.c Sat Nov 30 19:22:48 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_overflow.c,v 1.18 2012/03/13 21:13:32 christos Exp $ */ +/* $NetBSD: bt_overflow.c,v 1.19 2013/12/01 00:22:48 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_overflow.c,v 1.18 2012/03/13 21:13:32 christos Exp $); +__RCSID($NetBSD: bt_overflow.c,v 1.19 2013/12/01 00:22:48 christos Exp $); #include namespace.h #include sys/param.h @@ -97,7 +97,7 @@ __ovfl_get(BTREE *t, void *p, size_t *ss #endif /* Make the buffer bigger as necessary. */ if (*bufsz sz) { - *buf = (*buf == NULL ?
CVS commit: src/lib/libc/db/mpool
Module Name:src Committed By: christos Date: Fri Nov 22 16:25:51 UTC 2013 Modified Files: src/lib/libc/db/mpool: mpool.c Log Message: switch from circleq to tailq, from FreeBSD To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/db/mpool/mpool.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/mpool/mpool.c diff -u src/lib/libc/db/mpool/mpool.c:1.19 src/lib/libc/db/mpool/mpool.c:1.20 --- src/lib/libc/db/mpool/mpool.c:1.19 Wed Apr 22 14:44:06 2009 +++ src/lib/libc/db/mpool/mpool.c Fri Nov 22 11:25:51 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpool.c,v 1.19 2009/04/22 18:44:06 christos Exp $ */ +/* $NetBSD: mpool.c,v 1.20 2013/11/22 16:25:51 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: mpool.c,v 1.19 2009/04/22 18:44:06 christos Exp $); +__RCSID($NetBSD: mpool.c,v 1.20 2013/11/22 16:25:51 christos Exp $); #include namespace.h #include sys/queue.h @@ -93,9 +93,9 @@ mpool_open(void *key, int fd, pgno_t pag /* Allocate and initialize the MPOOL cookie. */ if ((mp = (MPOOL *)calloc(1, sizeof(MPOOL))) == NULL) return (NULL); - CIRCLEQ_INIT(mp-lqh); + TAILQ_INIT(mp-lqh); for (entry = 0; entry HASHSIZE; ++entry) - CIRCLEQ_INIT(mp-hqh[entry]); + TAILQ_INIT(mp-hqh[entry]); mp-maxcache = maxcache; mp-npages = (pgno_t)(sb.st_size / pagesize); mp-pagesize = pagesize; @@ -144,8 +144,8 @@ mpool_new( MPOOL *mp, pgno_t *pgnoaddr) bp-flags = MPOOL_PINNED; head = mp-hqh[HASHKEY(bp-pgno)]; - CIRCLEQ_INSERT_HEAD(head, bp, hq); - CIRCLEQ_INSERT_TAIL(mp-lqh, bp, q); + TAILQ_INSERT_HEAD(head, bp, hq); + TAILQ_INSERT_TAIL(mp-lqh, bp, q); return (bp-page); } @@ -186,10 +186,10 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int * of the lru chain. */ head = mp-hqh[HASHKEY(bp-pgno)]; - CIRCLEQ_REMOVE(head, bp, hq); - CIRCLEQ_INSERT_HEAD(head, bp, hq); - CIRCLEQ_REMOVE(mp-lqh, bp, q); - CIRCLEQ_INSERT_TAIL(mp-lqh, bp, q); + TAILQ_REMOVE(head, bp, hq); + TAILQ_INSERT_HEAD(head, bp, hq); + TAILQ_REMOVE(mp-lqh, bp, q); + TAILQ_INSERT_TAIL(mp-lqh, bp, q); /* Return a pinned page. */ bp-flags |= MPOOL_PINNED; @@ -220,8 +220,8 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int * of the lru chain. */ head = mp-hqh[HASHKEY(bp-pgno)]; - CIRCLEQ_INSERT_HEAD(head, bp, hq); - CIRCLEQ_INSERT_TAIL(mp-lqh, bp, q); + TAILQ_INSERT_HEAD(head, bp, hq); + TAILQ_INSERT_TAIL(mp-lqh, bp, q); /* Run through the user's filter. */ if (mp-pgin != NULL) @@ -266,8 +266,9 @@ mpool_close(MPOOL *mp) BKT *bp; /* Free up any space allocated to the lru pages. */ - while ((bp = mp-lqh.cqh_first) != (void *)mp-lqh) { - CIRCLEQ_REMOVE(mp-lqh, mp-lqh.cqh_first, q); + while (!TAILQ_EMPTY(mp-lqh)) { + bp = TAILQ_FIRST(mp-lqh); + TAILQ_REMOVE(mp-lqh, bp, q); free(bp); } @@ -286,8 +287,7 @@ mpool_sync(MPOOL *mp) BKT *bp; /* Walk the lru chain, flushing any dirty pages to disk. */ - for (bp = mp-lqh.cqh_first; - bp != (void *)mp-lqh; bp = bp-q.cqe_next) + TAILQ_FOREACH(bp, mp-lqh, q) if (bp-flags MPOOL_DIRTY mpool_write(mp, bp) == RET_ERROR) return (RET_ERROR); @@ -316,8 +316,7 @@ mpool_bkt(MPOOL *mp) * off any lists. If we don't find anything we grow the cache anyway. * The cache never shrinks. */ - for (bp = mp-lqh.cqh_first; - bp != (void *)mp-lqh; bp = bp-q.cqe_next) + TAILQ_FOREACH(bp, mp-lqh, q) if (!(bp-flags MPOOL_PINNED)) { /* Flush if dirty. */ if (bp-flags MPOOL_DIRTY @@ -328,8 +327,8 @@ mpool_bkt(MPOOL *mp) #endif /* Remove from the hash and lru queues. */ head = mp-hqh[HASHKEY(bp-pgno)]; - CIRCLEQ_REMOVE(head, bp, hq); - CIRCLEQ_REMOVE(mp-lqh, bp, q); + TAILQ_REMOVE(head, bp, hq); + TAILQ_REMOVE(mp-lqh, bp, q); #ifdef DEBUG { void *spage = bp-page; @@ -399,7 +398,7 @@ mpool_look(MPOOL *mp, pgno_t pgno) BKT *bp; head = mp-hqh[HASHKEY(pgno)]; - for (bp = head-cqh_first; bp != (void *)head; bp = bp-hq.cqe_next) + TAILQ_FOREACH(bp, head, hq) if (bp-pgno == pgno) { #ifdef STATISTICS ++mp-cachehit; @@ -443,8 +442,7 @@ mpool_stat(mp) sep = ; cnt = 0; - for (bp = mp-lqh.cqh_first; - bp != (void *)mp-lqh; bp = bp-q.cqe_next) { + TAILQ_FOREACH(bp, mp-lqh, q) { (void)fprintf(stderr, %s%d, sep, bp-pgno); if (bp-flags MPOOL_DIRTY) (void)fprintf(stderr, d);
CVS commit: src/lib/libc/db/btree
Module Name:src Committed By: ryoon Date: Wed Sep 4 13:03:22 UTC 2013 Modified Files: src/lib/libc/db/btree: bt_seq.c bt_utils.c btree.h Log Message: Fix typos from FreeMiNT's db-1.86 patch. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/db/btree/bt_seq.c cvs rdiff -u -r1.13 -r1.14 src/lib/libc/db/btree/bt_utils.c cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/btree/btree.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_seq.c diff -u src/lib/libc/db/btree/bt_seq.c:1.17 src/lib/libc/db/btree/bt_seq.c:1.18 --- src/lib/libc/db/btree/bt_seq.c:1.17 Thu Sep 11 12:58:00 2008 +++ src/lib/libc/db/btree/bt_seq.c Wed Sep 4 13:03:22 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_seq.c,v 1.17 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: bt_seq.c,v 1.18 2013/09/04 13:03:22 ryoon Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_seq.c,v 1.17 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: bt_seq.c,v 1.18 2013/09/04 13:03:22 ryoon Exp $); #include namespace.h #include sys/types.h @@ -92,7 +92,7 @@ __bt_seq(const DB *dbp, DBT *key, DBT *d } /* - * If scan unitialized as yet, or starting at a specific record, set + * If scan uninitialized as yet, or starting at a specific record, set * the scan to a specific key. Both __bt_seqset and __bt_seqadv pin * the page the cursor references if they're successful. */ Index: src/lib/libc/db/btree/bt_utils.c diff -u src/lib/libc/db/btree/bt_utils.c:1.13 src/lib/libc/db/btree/bt_utils.c:1.14 --- src/lib/libc/db/btree/bt_utils.c:1.13 Wed Sep 10 17:52:35 2008 +++ src/lib/libc/db/btree/bt_utils.c Wed Sep 4 13:03:22 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_utils.c,v 1.13 2008/09/10 17:52:35 joerg Exp $ */ +/* $NetBSD: bt_utils.c,v 1.14 2013/09/04 13:03:22 ryoon Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_utils.c,v 1.13 2008/09/10 17:52:35 joerg Exp $); +__RCSID($NetBSD: bt_utils.c,v 1.14 2013/09/04 13:03:22 ryoon Exp $); #include sys/param.h @@ -74,7 +74,7 @@ __bt_ret(BTREE *t, EPG *e, DBT *key, DBT bl = GETBLEAF(e-page, e-index); /* - * We must copy big keys/data to make them contigous. Otherwise, + * We must copy big keys/data to make them contiguous. Otherwise, * leave the page pinned and don't copy unless the user specified * concurrent access. */ Index: src/lib/libc/db/btree/btree.h diff -u src/lib/libc/db/btree/btree.h:1.16 src/lib/libc/db/btree/btree.h:1.17 --- src/lib/libc/db/btree/btree.h:1.16 Tue Aug 26 21:18:38 2008 +++ src/lib/libc/db/btree/btree.h Wed Sep 4 13:03:22 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: btree.h,v 1.16 2008/08/26 21:18:38 joerg Exp $ */ +/* $NetBSD: btree.h,v 1.17 2013/09/04 13:03:22 ryoon Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -185,7 +185,7 @@ typedef struct _rinternal { #define NRINTERNAL \ BTLALIGN(sizeof(recno_t) + sizeof(pgno_t)) -/* Copy a RINTERAL entry to the page. */ +/* Copy a RINTERNAL entry to the page. */ #define WR_RINTERNAL(p, nrecs, pgno) do {\ *(recno_t *)(void *)p = nrecs; \ p += sizeof(recno_t); \
CVS commit: src/lib/libc/db
Module Name:src Committed By: joerg Date: Tue Aug 9 13:03:36 UTC 2011 Modified Files: src/lib/libc/db: Makefile.inc Log Message: libc passes the relaxed array boundary check in clang now. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/lib/libc/db/Makefile.inc Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/Makefile.inc diff -u src/lib/libc/db/Makefile.inc:1.7 src/lib/libc/db/Makefile.inc:1.8 --- src/lib/libc/db/Makefile.inc:1.7 Thu May 26 12:56:29 2011 +++ src/lib/libc/db/Makefile.inc Tue Aug 9 13:03:36 2011 @@ -1,10 +1,8 @@ -# $NetBSD: Makefile.inc,v 1.7 2011/05/26 12:56:29 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.8 2011/08/09 13:03:36 joerg Exp $ # @(#)Makefile.inc 8.2 (Berkeley) 2/21/94 # CPPFLAGS+=-D__DBINTERFACE_PRIVATE -CWARNFLAGS.clang+= -Wno-array-bounds - .include ${.CURDIR}/db/btree/Makefile.inc .include ${.CURDIR}/db/db/Makefile.inc .include ${.CURDIR}/db/hash/Makefile.inc
CVS commit: src/lib/libc/db/recno
Module Name:src Committed By: christos Date: Sun Jun 26 22:18:17 UTC 2011 Modified Files: src/lib/libc/db/recno: rec_put.c Log Message: - Fix bug copying only 1 byte instead of the whole page number. Broke nvi joining lines that needed R_BIGDATA. - Fix from FreeBSD for nrec IAFTER. XXX: Should be pulled up to 5.x To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/recno/rec_put.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/recno/rec_put.c diff -u src/lib/libc/db/recno/rec_put.c:1.18 src/lib/libc/db/recno/rec_put.c:1.19 --- src/lib/libc/db/recno/rec_put.c:1.18 Mon Jun 20 05:11:17 2011 +++ src/lib/libc/db/recno/rec_put.c Sun Jun 26 18:18:16 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: rec_put.c,v 1.18 2011/06/20 09:11:17 mrg Exp $ */ +/* $NetBSD: rec_put.c,v 1.19 2011/06/26 22:18:16 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: rec_put.c,v 1.18 2011/06/20 09:11:17 mrg Exp $); +__RCSID($NetBSD: rec_put.c,v 1.19 2011/06/26 22:18:16 christos Exp $); #include namespace.h #include sys/types.h @@ -167,8 +167,14 @@ if ((status = __rec_iput(t, nrec - 1, fdata, flags)) != RET_SUCCESS) return (status); - if (flags == R_SETCURSOR) + switch (flags) { + case R_IAFTER: + nrec++; + break; + case R_SETCURSOR: t-bt_cursor.rcursor = nrec; + break; + } F_SET(t, R_MODIFIED); return (__rec_ret(t, NULL, nrec, key, NULL)); @@ -208,7 +214,7 @@ return (RET_ERROR); tdata.data = db; tdata.size = NOVFLSIZE; - memcpy(db, pg, sizeof(*db)); + memcpy(db, pg, sizeof(pg)); _DBFIT(data-size, uint32_t); *(uint32_t *)(void *)(db + sizeof(pgno_t)) = (uint32_t)data-size;
CVS commit: src/lib/libc/db/btree
Module Name:src Committed By: christos Date: Sun Jun 26 22:20:31 UTC 2011 Modified Files: src/lib/libc/db/btree: bt_overflow.c bt_put.c Log Message: - use sizeof(var) instead of sizeof(type) - remove useless cast To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/btree/bt_overflow.c cvs rdiff -u -r1.19 -r1.20 src/lib/libc/db/btree/bt_put.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_overflow.c diff -u src/lib/libc/db/btree/bt_overflow.c:1.16 src/lib/libc/db/btree/bt_overflow.c:1.17 --- src/lib/libc/db/btree/bt_overflow.c:1.16 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/btree/bt_overflow.c Sun Jun 26 18:20:31 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_overflow.c,v 1.16 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: bt_overflow.c,v 1.17 2011/06/26 22:20:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_overflow.c,v 1.16 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: bt_overflow.c,v 1.17 2011/06/26 22:20:31 christos Exp $); #include namespace.h #include sys/param.h @@ -87,7 +87,7 @@ uint32_t sz, nb, plen; size_t temp; - memmove(pg, p, sizeof(pgno_t)); + memmove(pg, p, sizeof(pg)); memmove(sz, (char *)p + sizeof(pgno_t), sizeof(uint32_t)); *ssz = sz; @@ -97,7 +97,7 @@ #endif /* Make the buffer bigger as necessary. */ if (*bufsz sz) { - *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz)); + *buf = (*buf == NULL ? malloc(sz) : realloc(*buf, sz)); if (*buf == NULL) return (RET_ERROR); *bufsz = sz; @@ -200,7 +200,7 @@ uint32_t sz, plen; size_t temp; - (void)memmove(pg, p, sizeof(pgno_t)); + (void)memmove(pg, p, sizeof(pg)); (void)memmove(sz, (char *)p + sizeof(pgno_t), sizeof(uint32_t)); #ifdef DEBUG Index: src/lib/libc/db/btree/bt_put.c diff -u src/lib/libc/db/btree/bt_put.c:1.19 src/lib/libc/db/btree/bt_put.c:1.20 --- src/lib/libc/db/btree/bt_put.c:1.19 Thu Feb 12 01:40:14 2009 +++ src/lib/libc/db/btree/bt_put.c Sun Jun 26 18:20:31 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_put.c,v 1.19 2009/02/12 06:40:14 lukem Exp $ */ +/* $NetBSD: bt_put.c,v 1.20 2011/06/26 22:20:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_put.c,v 1.19 2009/02/12 06:40:14 lukem Exp $); +__RCSID($NetBSD: bt_put.c,v 1.20 2011/06/26 22:20:31 christos Exp $); #include namespace.h #include sys/types.h @@ -127,7 +127,7 @@ return (RET_ERROR); tkey.data = kb; tkey.size = NOVFLSIZE; - memmove(kb, pg, sizeof(pgno_t)); + memmove(kb, pg, sizeof(pg)); memmove(kb + sizeof(pgno_t), key-size, sizeof(uint32_t)); dflags |= P_BIGKEY; @@ -138,7 +138,7 @@ return (RET_ERROR); tdata.data = db; tdata.size = NOVFLSIZE; - memmove(db, pg, sizeof(pgno_t)); + memmove(db, pg, sizeof(pg)); _DBFIT(data-size, uint32_t); temp = (uint32_t)data-size; (void)memmove(db + sizeof(pgno_t),
CVS commit: src/lib/libc/db
Module Name:src Committed By: christos Date: Sun Apr 17 23:12:38 UTC 2011 Modified Files: src/lib/libc/db/btree: bt_open.c src/lib/libc/db/hash: hash_page.c Log Message: Correct check for snprintf() overflow via Maksymilian Arciemowicz from FreeBSD. (the bt one was ok, but set errno and make it the same for consistency). [to be pulled up] To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/lib/libc/db/btree/bt_open.c cvs rdiff -u -r1.23 -r1.24 src/lib/libc/db/hash/hash_page.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_open.c diff -u src/lib/libc/db/btree/bt_open.c:1.24 src/lib/libc/db/btree/bt_open.c:1.25 --- src/lib/libc/db/btree/bt_open.c:1.24 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/btree/bt_open.c Sun Apr 17 19:12:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_open.c,v 1.24 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: bt_open.c,v 1.25 2011/04/17 23:12:38 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_open.c,v 1.24 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: bt_open.c,v 1.25 2011/04/17 23:12:38 christos Exp $); /* * Implementation of btree access method for 4.4BSD. @@ -391,7 +391,7 @@ tmp(void) { sigset_t set, oset; - size_t len; + int len; int fd; char *envtmp; char path[PATH_MAX]; @@ -403,8 +403,10 @@ len = snprintf(path, sizeof(path), %s/bt.XX, envtmp ? envtmp : _PATH_TMP); - if (len = sizeof(path)) + if (len 0 || (size_t)len = sizeof(path)) { + errno = ENAMETOOLONG; return -1; + } (void)sigfillset(set); (void)sigprocmask(SIG_BLOCK, set, oset); Index: src/lib/libc/db/hash/hash_page.c diff -u src/lib/libc/db/hash/hash_page.c:1.23 src/lib/libc/db/hash/hash_page.c:1.24 --- src/lib/libc/db/hash/hash_page.c:1.23 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/hash/hash_page.c Sun Apr 17 19:12:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_page.c,v 1.23 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: hash_page.c,v 1.24 2011/04/17 23:12:38 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: hash_page.c,v 1.23 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: hash_page.c,v 1.24 2011/04/17 23:12:38 christos Exp $); /* * PACKAGE: hashing @@ -869,15 +869,19 @@ sigset_t set, oset; char *envtmp; char namestr[PATH_MAX]; + int len; if (issetugid()) envtmp = NULL; else envtmp = getenv(TMPDIR); - if (-1 == snprintf(namestr, sizeof(namestr), %s/_hashXX, - envtmp ? envtmp : _PATH_TMP)) + len = snprintf(namestr, sizeof(namestr), %s/_hashXX, + envtmp ? envtmp : _PATH_TMP); + if (len 0 || (size_t)len = sizeof(namestr)) { + errno = ENAMETOOLONG; return -1; + } /* Block signals; make sure file goes away at process exit. */ (void)sigfillset(set);
CVS commit: src/lib/libc/db/man
Module Name:src Committed By: jruoho Date: Thu Dec 16 11:49:35 UTC 2010 Modified Files: src/lib/libc/db/man: mpool.3 Log Message: Use .Fn. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/libc/db/man/mpool.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/man/mpool.3 diff -u src/lib/libc/db/man/mpool.3:1.9 src/lib/libc/db/man/mpool.3:1.10 --- src/lib/libc/db/man/mpool.3:1.9 Thu Aug 7 16:42:43 2003 +++ src/lib/libc/db/man/mpool.3 Thu Dec 16 11:49:35 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: mpool.3,v 1.9 2003/08/07 16:42:43 agc Exp $ +.\ $NetBSD: mpool.3,v 1.10 2010/12/16 11:49:35 jruoho Exp $ .\ .\ Copyright (c) 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\ .\ @(#)mpool.3 8.1 (Berkeley) 6/4/93 .\ -.Dd April 17, 2003 +.Dd December 16, 2010 .Dt MPOOL 3 .Os .Sh NAME @@ -67,7 +67,7 @@ The buffers may be shared between processes. .Pp The function -.Nm mpool_open +.Fn mpool_open initializes a memory pool. The .Fa key @@ -105,7 +105,7 @@ processes sharing the file. .Pp The -.Nm mpool_filter +.Fn mpool_filter function is intended to make transparent input and output processing of the pages possible. If the @@ -122,7 +122,7 @@ written. .Pp The function -.Nm mpool_new +.Fn mpool_new takes an MPOOL pointer and an address as arguments. If a new page can be allocated, a pointer to the page is returned and the page number is stored into the @@ -133,7 +133,7 @@ is returned and errno is set. .Pp The function -.Nm mpool_get +.Fn mpool_get takes a MPOOL pointer and a page number as arguments. If the page exists, a pointer to the page is returned. Otherwise, @@ -142,14 +142,14 @@ The flags parameter is not currently used. .Pp The function -.Nm mpool_put +.Fn mpool_put unpins the page referenced by .Fa pgaddr . .Fa pgaddr must be an address previously returned by -.Nm mpool_get +.Fn mpool_get or -.Nm mpool_new . +.Fn mpool_new . The flag value is specified by or'ing any of the following values: .Bl -tag -width MPOOL_DIRTYX -offset indent .It Dv MPOOL_DIRTY @@ -157,35 +157,35 @@ file. .El .Pp -.Nm mpool_put +.Fn mpool_put returns 0 on success and \-1 if an error occurs. .Pp The function -.Nm mpool_sync +.Fn mpool_sync writes all modified pages associated with the MPOOL pointer to the backing file. -.Nm mpool_sync +.Fn mpool_sync returns 0 on success and \-1 if an error occurs. .Pp The -.Nm mpool_close +.Fn mpool_close function frees up any allocated memory associated with the memory pool cookie. Modified pages are .Em not written to the backing file. -.Nm mpool_close +.Fn mpool_close returns 0 on success and \-1 if an error occurs. .Sh ERRORS The -.Nm mpool_open +.Fn mpool_open function may fail and set .Va errno for any of the errors specified for the library routine .Xr malloc 3 . .Pp The -.Nm mpool_get +.Fn mpool_get function may fail and set .Va errno for the following: @@ -195,9 +195,9 @@ .El .Pp The -.Nm mpool_new +.Fn mpool_new and -.Nm mpool_get +.Fn mpool_get functions may fail and set .Va errno for any of the errors specified for the library routines @@ -207,14 +207,14 @@ .Xr malloc 3 . .Pp The -.Nm mpool_sync +.Fn mpool_sync function may fail and set .Va errno for any of the errors specified for the library routine .Xr write 2 . .Pp The -.Nm mpool_close +.Fn mpool_close function may fail and set .Va errno for any of the errors specified for the library routine
CVS commit: src/lib/libc/db/man
Module Name:src Committed By: jruoho Date: Thu Dec 16 11:57:20 UTC 2010 Modified Files: src/lib/libc/db/man: hash.3 Log Message: Fix the references and -offset indent. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/lib/libc/db/man/hash.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/man/hash.3 diff -u src/lib/libc/db/man/hash.3:1.13 src/lib/libc/db/man/hash.3:1.14 --- src/lib/libc/db/man/hash.3:1.13 Mon Mar 22 19:30:53 2010 +++ src/lib/libc/db/man/hash.3 Thu Dec 16 11:57:20 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: hash.3,v 1.13 2010/03/22 19:30:53 joerg Exp $ +.\ $NetBSD: hash.3,v 1.14 2010/12/16 11:57:20 jruoho Exp $ .\ .\ Copyright (c) 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\ .\ @(#)hash.3 8.6 (Berkeley) 8/18/94 .\ -.Dd September 5, 2008 +.Dd December 16, 2010 .Dt HASH 3 .Os .Sh NAME @@ -53,8 +53,8 @@ .Fn dbopen is defined in the .In db.h -include file as follows: -.Bd -literal +header as follows: +.Bd -literal -offset indent typedef struct { u_int bsize; u_int ffactor; @@ -152,16 +152,21 @@ .Xr recno 3 .Pp .Rs -.%T Dynamic Hash Tables +.%T Dynamic Hash Tables .%A Per-Ake Larson .%J Communications of the ACM .%D April 1988 +.%N Issue 4 +.%V Volume 31 .Re .Rs -.%T A New Hash Package for UNIX +.%T A New Hash Package for UNIX .%A Margo Seltzer -.%J USENIX Proceedings -.%D Winter 1991 +.%I USENIX Association +.%B Proceedings of the 1991 Winter USENIX Technical Conference +.%D January 1991 +.%P 173-184 +.%U http://www.usenix.org/publications/library/proceedings/seltzer2.pdf .Re .Sh BUGS Only big and little endian byte order is supported.
CVS commit: src/lib/libc/db/man
Module Name:src Committed By: jruoho Date: Thu Dec 16 12:08:16 UTC 2010 Modified Files: src/lib/libc/db/man: dbopen.3 Log Message: .Fn, offset indent, complete reference. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/man/dbopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/man/dbopen.3 diff -u src/lib/libc/db/man/dbopen.3:1.18 src/lib/libc/db/man/dbopen.3:1.19 --- src/lib/libc/db/man/dbopen.3:1.18 Mon Mar 22 19:30:53 2010 +++ src/lib/libc/db/man/dbopen.3 Thu Dec 16 12:08:16 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: dbopen.3,v 1.18 2010/03/22 19:30:53 joerg Exp $ +.\ $NetBSD: dbopen.3,v 1.19 2010/12/16 12:08:16 jruoho Exp $ .\ .\ Copyright (c) 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\ .\ @(#)dbopen.3 8.5 (Berkeley) 1/2/94 .\ -.Dd April 17, 2003 +.Dd December 16, 2010 .Dt DBOPEN 3 .Os .Sh NAME @@ -60,8 +60,9 @@ and .Xr recno 3 . .Pp -.Nm -opens +The +.Fn dbopen +function opens .Fa file for reading and/or writing. Files never intended to be preserved on disk may be created by setting @@ -134,15 +135,16 @@ .Dv NULL , each access method will use defaults appropriate for the system and the access method. -.Pp -.Nm -returns a pointer to a DB structure on success and +.Ss The DB Structure +The +.Fn dbopen +function returns a pointer to a DB structure on success and .Dv NULL on error. The DB structure is defined in the .In db.h include file, and contains at least the following fields: -.Bd -literal +.Bd -literal -offset indent typedef struct { DBTYPE type; int (*close)(const DB *db); @@ -162,7 +164,7 @@ .Nm , and sometimes one or more pointers to key/data structures and a flag value. -.Bl -tag -width closex +.Bl -tag -width closex -offset indent .It Fa type The type of the underlying access method (and file format). .It Fa close @@ -420,10 +422,10 @@ .Va errno ) and 0 on success. .El -.Ss KEY/DATA PAIRS +.Ss Key/data Pairs Access to all file types is based on key/data pairs. Both keys and data are represented by the following data structure: -.Bd -literal +.Bd -literal -offset indent typedef struct { void *data; size_t size; @@ -431,7 +433,7 @@ .Ed .Pp The elements of the DBT structure are defined as follows: -.Bl -tag -width datax +.Bl -tag -width datax -offset indent .It Fa data A pointer to a byte string. .It Fa size @@ -515,11 +517,13 @@ .Xr recno 3 .Pp .Rs -.%T LIBTP: Portable, Modular Transactions for UNIX +.%T LIBTP: Portable, Modular Transactions for UNIX .%A Margo Seltzer .%A Michael Olson -.%J USENIX proceedings -.%D Winter 1992 +.%I USENIX Association +.%B Proceedings of the 1992 Winter USENIX Technical Conference +.%D 1992 +.%P 9-25 .Re .Sh BUGS The typedef DBT is a mnemonic for
CVS commit: src/lib/libc/db/man
Module Name:src Committed By: jruoho Date: Wed May 5 06:55:57 UTC 2010 Modified Files: src/lib/libc/db/man: dbm_clearerr.3 Log Message: Note the POSIX compliance (already since SUSv2, '97). To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/lib/libc/db/man/dbm_clearerr.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/man/dbm_clearerr.3 diff -u src/lib/libc/db/man/dbm_clearerr.3:1.4 src/lib/libc/db/man/dbm_clearerr.3:1.5 --- src/lib/libc/db/man/dbm_clearerr.3:1.4 Wed Apr 30 13:10:50 2008 +++ src/lib/libc/db/man/dbm_clearerr.3 Wed May 5 06:55:57 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: dbm_clearerr.3,v 1.4 2008/04/30 13:10:50 martin Exp $ +.\ $NetBSD: dbm_clearerr.3,v 1.5 2010/05/05 06:55:57 jruoho Exp $ .\ .\ Copyright (c) 2004 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -27,7 +27,7 @@ .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\ POSSIBILITY OF SUCH DAMAGE. .\ -.Dd April 30, 2004 +.Dd May 5, 2010 .Dt DBM_CLEARERR 3 .Os .Sh NAME @@ -298,7 +298,9 @@ and .Fn dbm_store functions conform to -.St -xpg4.2 . +.St -xpg4.2 +and +.St -susv2 . The .Fn dbm_dirfno function is an extension.
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: christos Date: Thu Apr 23 22:09:23 UTC 2009 Modified Files: src/lib/libc/db/hash: hash_buf.c Log Message: correct cast to size_t. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/db/hash/hash_buf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash_buf.c diff -u src/lib/libc/db/hash/hash_buf.c:1.17 src/lib/libc/db/hash/hash_buf.c:1.18 --- src/lib/libc/db/hash/hash_buf.c:1.17 Wed Apr 22 23:49:39 2009 +++ src/lib/libc/db/hash/hash_buf.c Thu Apr 23 18:09:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_buf.c,v 1.17 2009/04/23 03:49:39 agc Exp $ */ +/* $NetBSD: hash_buf.c,v 1.18 2009/04/23 22:09:23 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: hash_buf.c,v 1.17 2009/04/23 03:49:39 agc Exp $); +__RCSID($NetBSD: hash_buf.c,v 1.18 2009/04/23 22:09:23 christos Exp $); /* * PACKAGE: hash @@ -315,7 +315,7 @@ /* Check if we are freeing stuff */ if (do_free) { if (bp-page) { -(void)memset(bp-page, 0, (unsigned)hashp-BSIZE); +(void)memset(bp-page, 0, (size_t)hashp-BSIZE); free(bp-page); } BUF_REMOVE(bp);
CVS commit: src/lib/libc/db
Module Name:src Committed By: christos Date: Wed Apr 22 18:44:06 UTC 2009 Modified Files: src/lib/libc/db/btree: bt_split.c src/lib/libc/db/hash: hash_buf.c src/lib/libc/db/mpool: mpool.c Log Message: Avoid information leaks by zeroing memory, from FreeBSD (we had done some already) To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/btree/bt_split.c cvs rdiff -u -r1.14 -r1.15 src/lib/libc/db/hash/hash_buf.c cvs rdiff -u -r1.18 -r1.19 src/lib/libc/db/mpool/mpool.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/btree/bt_split.c diff -u src/lib/libc/db/btree/bt_split.c:1.18 src/lib/libc/db/btree/bt_split.c:1.19 --- src/lib/libc/db/btree/bt_split.c:1.18 Thu Feb 12 01:41:40 2009 +++ src/lib/libc/db/btree/bt_split.c Wed Apr 22 14:44:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: bt_split.c,v 1.18 2009/02/12 06:41:40 lukem Exp $ */ +/* $NetBSD: bt_split.c,v 1.19 2009/04/22 18:44:06 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: bt_split.c,v 1.18 2009/02/12 06:41:40 lukem Exp $); +__RCSID($NetBSD: bt_split.c,v 1.19 2009/04/22 18:44:06 christos Exp $); #include namespace.h #include sys/types.h @@ -383,7 +383,7 @@ } /* Put the new left page for the split into place. */ - if ((l = (PAGE *)malloc(t-bt_psize)) == NULL) { + if ((l = calloc(1, t-bt_psize)) == NULL) { mpool_put(t-bt_mp, r, 0); return (NULL); } Index: src/lib/libc/db/hash/hash_buf.c diff -u src/lib/libc/db/hash/hash_buf.c:1.14 src/lib/libc/db/hash/hash_buf.c:1.15 --- src/lib/libc/db/hash/hash_buf.c:1.14 Wed Sep 10 13:52:35 2008 +++ src/lib/libc/db/hash/hash_buf.c Wed Apr 22 14:44:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_buf.c,v 1.14 2008/09/10 17:52:35 joerg Exp $ */ +/* $NetBSD: hash_buf.c,v 1.15 2009/04/22 18:44:06 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: hash_buf.c,v 1.14 2008/09/10 17:52:35 joerg Exp $); +__RCSID($NetBSD: hash_buf.c,v 1.15 2009/04/22 18:44:06 christos Exp $); /* * PACKAGE: hash @@ -313,8 +313,10 @@ } /* Check if we are freeing stuff */ if (do_free) { - if (bp-page) + if (bp-page) { +(void)memset(bp-page, 0, hashp-BSIZE); free(bp-page); + } BUF_REMOVE(bp); free(bp); bp = LRU; Index: src/lib/libc/db/mpool/mpool.c diff -u src/lib/libc/db/mpool/mpool.c:1.18 src/lib/libc/db/mpool/mpool.c:1.19 --- src/lib/libc/db/mpool/mpool.c:1.18 Thu Sep 11 08:58:00 2008 +++ src/lib/libc/db/mpool/mpool.c Wed Apr 22 14:44:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: mpool.c,v 1.18 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: mpool.c,v 1.19 2009/04/22 18:44:06 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: mpool.c,v 1.18 2008/09/11 12:58:00 joerg Exp $); +__RCSID($NetBSD: mpool.c,v 1.19 2009/04/22 18:44:06 christos Exp $); #include namespace.h #include sys/queue.h @@ -341,7 +341,7 @@ return (bp); } -new: if ((bp = (BKT *)malloc((size_t)(sizeof(BKT) + mp-pagesize))) == NULL) +new: if ((bp = calloc(1, (size_t)(sizeof(BKT) + mp-pagesize))) == NULL) return (NULL); #ifdef STATISTICS ++mp-pagealloc;
CVS commit: src/lib/libc/db/hash
Module Name:src Committed By: agc Date: Thu Apr 23 03:49:39 UTC 2009 Modified Files: src/lib/libc/db/hash: hash_buf.c Log Message: Cast the arg to an unsigned value to let this compile To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/hash/hash_buf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/hash/hash_buf.c diff -u src/lib/libc/db/hash/hash_buf.c:1.16 src/lib/libc/db/hash/hash_buf.c:1.17 --- src/lib/libc/db/hash/hash_buf.c:1.16 Wed Apr 22 21:52:59 2009 +++ src/lib/libc/db/hash/hash_buf.c Thu Apr 23 03:49:39 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: hash_buf.c,v 1.16 2009/04/22 21:52:59 njoly Exp $ */ +/* $NetBSD: hash_buf.c,v 1.17 2009/04/23 03:49:39 agc Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include sys/cdefs.h -__RCSID($NetBSD: hash_buf.c,v 1.16 2009/04/22 21:52:59 njoly Exp $); +__RCSID($NetBSD: hash_buf.c,v 1.17 2009/04/23 03:49:39 agc Exp $); /* * PACKAGE: hash @@ -315,7 +315,7 @@ /* Check if we are freeing stuff */ if (do_free) { if (bp-page) { -(void)memset(bp-page, 0, hashp-BSIZE); +(void)memset(bp-page, 0, (unsigned)hashp-BSIZE); free(bp-page); } BUF_REMOVE(bp);
CVS commit: src/lib/libc/db/man
Module Name:src Committed By: joerg Date: Sat Apr 11 20:39:15 UTC 2009 Modified Files: src/lib/libc/db/man: dbopen.3 Log Message: -width needs an argument, so provide one. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/db/man/dbopen.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/lib/libc/db/man/dbopen.3 diff -u src/lib/libc/db/man/dbopen.3:1.16 src/lib/libc/db/man/dbopen.3:1.17 --- src/lib/libc/db/man/dbopen.3:1.16 Tue Aug 31 17:11:33 2004 +++ src/lib/libc/db/man/dbopen.3 Sat Apr 11 20:39:15 2009 @@ -1,4 +1,4 @@ -.\ $NetBSD: dbopen.3,v 1.16 2004/08/31 17:11:33 uwe Exp $ +.\ $NetBSD: dbopen.3,v 1.17 2009/04/11 20:39:15 joerg Exp $ .\ .\ Copyright (c) 1990, 1993 .\ The Regents of the University of California. All rights reserved. @@ -401,7 +401,7 @@ routine has no effect and will always succeed. .Pp The flag value may be set to the following value: -.Bl -tag -width +.Bl -tag -width .Dv R_RECNOSYNC .It Dv R_RECNOSYNC If the .Dv DB_RECNO