]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: (zfs) keep bufferes read-only
authorKarel Zak <kzak@redhat.com>
Tue, 22 Sep 2015 13:27:39 +0000 (15:27 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 Sep 2015 09:10:09 +0000 (11:10 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/superblocks/zfs.c

index 8f82d1e6bd27b7dc3b97f33cf9a386562e82e219..60e6c7aa874dd2dc1354a02929163d6d9a08f3de 100644 (file)
@@ -70,9 +70,10 @@ struct nvlist {
 
 static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
 {
+       unsigned char *p, buff[4096];
        struct nvlist *nvl;
        struct nvpair *nvp;
-       size_t left = 4096;
+       size_t left = sizeof(buff);
        int found = 0;
 
        offset = (offset & ~(VDEV_LABEL_SIZE - 1)) + VDEV_LABEL_NVPAIR;
@@ -81,10 +82,14 @@ static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
         * the first 4k (left) of the nvlist.  This is true for all pools
         * I've seen, and simplifies this code somewhat, because we don't
         * have to handle an nvpair crossing a buffer boundary. */
-       nvl = (struct nvlist *)blkid_probe_get_buffer(pr, offset, left);
-       if (nvl == NULL)
+       p = blkid_probe_get_buffer(pr, offset, left);
+       if (!p)
                return;
 
+       /* libblkid buffers are strictly readonly, but the code below modifies nvpair etc. */
+       memcpy(buff, p, sizeof(buff));
+       nvl = (struct nvlist *) buff;
+
        nvdebug("zfs_extract: nvlist offset %llu\n", offset);
 
        nvp = &nvl->nvl_nvpair;