]> git.proxmox.com Git - zfs-grub.git/blob - pvepatches/zfs.c-Avoid-divisions-by-zero.patch
13ef8742765480f9548a0ef0fb6ada768f7c5ef9
[zfs-grub.git] / pvepatches / zfs.c-Avoid-divisions-by-zero.patch
1 From 475bffeae67fa0f6787c33147c120b40e89b1985 Mon Sep 17 00:00:00 2001
2 From: Vladimir Serbinenko <phcoder@gmail.com>
3 Date: Tue, 20 Jan 2015 16:46:55 +0000
4 Subject: * grub-core/fs/zfs.c: Avoid divisions by zero.
5
6 ---
7 (limited to 'grub-core/fs/zfs')
8
9 diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
10 index cfb25c0..c943b52 100644
11 --- a/grub-core/fs/zfs/zfs.c
12 +++ b/grub-core/fs/zfs/zfs.c
13 @@ -1501,6 +1501,9 @@ read_device (grub_uint64_t offset, struct grub_zfs_device_desc *desc,
14 return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
15 "raidz%d is not supported", desc->nparity);
16
17 + if (desc->n_children <= desc->nparity || desc->n_children < 1)
18 + return grub_error(GRUB_ERR_BAD_FS, "too little devices for given parity");
19 +
20 orig_s = (((len + (1 << desc->ashift) - 1) >> desc->ashift)
21 + (desc->n_children - desc->nparity) - 1);
22 s = orig_s;
23 @@ -2804,6 +2807,9 @@ dnode_get_path (struct subvolume *subvol, const char *path_in, dnode_end_t *dn,
24 dnode_path->dn.endian)
25 << SPA_MINBLOCKSHIFT);
26
27 + if (blksz == 0)
28 + return grub_error(GRUB_ERR_BAD_FS, "0-sized block");
29 +
30 sym_value = grub_malloc (sym_sz);
31 if (!sym_value)
32 return grub_errno;
33 @@ -3798,6 +3804,12 @@ grub_zfs_read (grub_file_t file, char *buf, grub_size_t len)
34 blksz = grub_zfs_to_cpu16 (data->dnode.dn.dn_datablkszsec,
35 data->dnode.endian) << SPA_MINBLOCKSHIFT;
36
37 + if (blksz == 0)
38 + {
39 + grub_error (GRUB_ERR_BAD_FS, "0-sized block");
40 + return -1;
41 + }
42 +
43 /*
44 * Entire Dnode is too big to fit into the space available. We
45 * will need to read it in chunks. This could be optimized to
46 --
47 cgit v0.9.0.2