]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
zfs: add missing NULL check and fix incorrect buffer overwrite
authorAndrei Borzenkov <arvidjaar@gmail.com>
Sun, 3 May 2015 15:55:13 +0000 (18:55 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Sun, 3 May 2015 15:57:32 +0000 (18:57 +0300)
grub_memset should zero out padding after data end. It is not clear
why it is needed at all - ZFS block is at least 512 bytes and power
of two, so it is always multiple of 16 bytes. This grub_memset
apparently never did anything.

grub-core/fs/zfs/zfs.c

index 03d587d8c5d585d12f95da02400929755c06b4d4..08ed453a66c0a22fb171ec704b03dcf5352b025c 100644 (file)
@@ -1887,14 +1887,12 @@ zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf,
                       "compression algorithm %s not supported\n", decomp_table[comp].name);
 
   if (comp != ZIO_COMPRESS_OFF)
-    {
-      /* It's not really necessary to align to 16, just for safety.  */
-      compbuf = grub_malloc (ALIGN_UP (psize, 16));
-      if (! compbuf)
-       return grub_errno;
-    }
+    /* It's not really necessary to align to 16, just for safety.  */
+    compbuf = grub_malloc (ALIGN_UP (psize, 16));
   else
     compbuf = *buf = grub_malloc (lsize);
+  if (! compbuf)
+    return grub_errno;
 
   grub_dprintf ("zfs", "endian = %d\n", endian);
   if (BP_IS_EMBEDDED(bp))
@@ -1902,7 +1900,9 @@ zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf,
   else
     {
       err = zio_read_data (bp, endian, compbuf, data);
-      grub_memset (compbuf, 0, ALIGN_UP (psize, 16) - psize);
+      /* FIXME is it really necessary? */
+      if (comp != ZIO_COMPRESS_OFF)
+       grub_memset (compbuf + psize, 0, ALIGN_UP (psize, 16) - psize);
     }
   if (err)
     {