dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0110-libblkid-zfs-keep-bufferes-read-only.patch

531551
From eeb629102da9a9a916d201bbd5f13ee7ad23844d Mon Sep 17 00:00:00 2001
531551
From: Karel Zak <kzak@redhat.com>
531551
Date: Tue, 22 Sep 2015 15:27:39 +0200
531551
Subject: [PATCH 110/116] libblkid: (zfs) keep bufferes read-only
531551
531551
Upstream: https://github.com/karelzak/util-linux/commit/9325a8be9e55cc01d9f580e14dd2193829245183
531551
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1392661
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 libblkid/src/superblocks/zfs.c | 11 ++++++++---
531551
 1 file changed, 8 insertions(+), 3 deletions(-)
531551
531551
diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c
531551
index 9b5601e..8e88b39 100644
531551
--- a/libblkid/src/superblocks/zfs.c
531551
+++ b/libblkid/src/superblocks/zfs.c
531551
@@ -70,9 +70,10 @@ struct nvlist {
531551
 
531551
 static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
531551
 {
531551
+	unsigned char *p, buff[4096];
531551
 	struct nvlist *nvl;
531551
 	struct nvpair *nvp;
531551
-	size_t left = 4096;
531551
+	size_t left = sizeof(buff);
531551
 	int found = 0;
531551
 
531551
 	offset = (offset & ~(VDEV_LABEL_SIZE - 1)) + VDEV_LABEL_NVPAIR;
531551
@@ -81,10 +82,14 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
531551
 	 * the first 4k (left) of the nvlist.  This is true for all pools
531551
 	 * I've seen, and simplifies this code somewhat, because we don't
531551
 	 * have to handle an nvpair crossing a buffer boundary. */
531551
-	nvl = (struct nvlist *)blkid_probe_get_buffer(pr, offset, left);
531551
-	if (nvl == NULL)
531551
+	p = blkid_probe_get_buffer(pr, offset, left);
531551
+	if (!p)
531551
 		return;
531551
 
531551
+	/* libblkid buffers are strictly readonly, but the code below modifies nvpair etc. */
531551
+	memcpy(buff, p, sizeof(buff));
531551
+	nvl = (struct nvlist *) buff;
531551
+
531551
 	nvdebug("zfs_extract: nvlist offset %llu\n", offset);
531551
 
531551
 	nvp = &nvl->nvl_nvpair;
531551
-- 
531551
2.9.3
531551