diff options
author | ngie <ngie@FreeBSD.org> | 2017-02-10 06:31:31 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2017-02-10 06:31:31 +0000 |
commit | 84761e71d50647a6c1a71f36b39a73c2fbe8c558 (patch) | |
tree | eaaf55971b8cd26be68e9c1ef6ca1f6477215a77 /lib/libc/db | |
parent | 5c4570910d8ef05fb25921789683e56a2a6382ad (diff) | |
download | FreeBSD-src-84761e71d50647a6c1a71f36b39a73c2fbe8c558.zip FreeBSD-src-84761e71d50647a6c1a71f36b39a73c2fbe8c558.tar.gz |
MFC r306349:
r306349 (by pfg):
hash(3): protect in-memory page when using cross-endianness.
When writing out pages in the "other endian" format, make a copy
instead of trashing the in-memory one.
Obtained from: NetBSD (CVS rev. 1.29)
Diffstat (limited to 'lib/libc/db')
-rw-r--r-- | lib/libc/db/hash/hash_page.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index a2bb7cf..ec2d184 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -572,7 +572,9 @@ __get_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_disk, int __put_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_bitmap) { - int fd, page, size, wsize; + int fd, page, size; + ssize_t wsize; + char pbuf[MAX_BSIZE]; size = hashp->BSIZE; if ((hashp->fp == -1) && open_temp(hashp)) @@ -582,15 +584,18 @@ __put_page(HTAB *hashp, char *p, u_int32_t bucket, int is_bucket, int is_bitmap) if (hashp->LORDER != BYTE_ORDER) { int i, max; + memcpy(pbuf, p, size); if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((int *)p)[i]); + M_32_SWAP(((int *)pbuf)[i]); } else { - max = ((u_int16_t *)p)[0] + 2; + uint16_t *bp = (uint16_t *)(void *)pbuf; + max = bp[0] + 2; for (i = 0; i <= max; i++) - M_16_SWAP(((u_int16_t *)p)[i]); + M_16_SWAP(bp[i]); } + p = pbuf; } if (is_bucket) page = BUCKET_TO_PAGE(bucket); |