Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Sep 2016 16:06:50 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r306349 - head/lib/libc/db/hash
Message-ID:  <201609261606.u8QG6ogU035104@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Mon Sep 26 16:06:50 2016
New Revision: 306349
URL: https://svnweb.freebsd.org/changeset/base/306349

Log:
  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)

Modified:
  head/lib/libc/db/hash/hash_page.c

Modified: head/lib/libc/db/hash/hash_page.c
==============================================================================
--- head/lib/libc/db/hash/hash_page.c	Mon Sep 26 15:45:30 2016	(r306348)
+++ head/lib/libc/db/hash/hash_page.c	Mon Sep 26 16:06:50 2016	(r306349)
@@ -572,7 +572,9 @@ __get_page(HTAB *hashp, char *p, u_int32
 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
 	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609261606.u8QG6ogU035104>