* grub-core/fs/btrfs.c: Avoid divisions by zero.
This commit is contained in:
parent
065ed900d4
commit
9deb46e363
2 changed files with 25 additions and 14 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/fs/btrfs.c: Avoid divisions by zero.
|
||||||
|
|
||||||
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
|
2015-01-20 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/lib/pbkdf2.c (grub_crypto_pbkdf2): Check that hash len is not 0.
|
* grub-core/lib/pbkdf2.c (grub_crypto_pbkdf2): Check that hash len is not 0.
|
||||||
|
|
|
@ -680,6 +680,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
||||||
grub_uint64_t stripen;
|
grub_uint64_t stripen;
|
||||||
grub_uint64_t stripe_offset;
|
grub_uint64_t stripe_offset;
|
||||||
grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset);
|
grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset);
|
||||||
|
grub_uint64_t chunk_stripe_length;
|
||||||
|
grub_uint16_t nstripes;
|
||||||
unsigned redundancy = 1;
|
unsigned redundancy = 1;
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
|
|
||||||
|
@ -690,15 +692,17 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
||||||
"couldn't find the chunk descriptor");
|
"couldn't find the chunk descriptor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nstripes = grub_le_to_cpu16 (chunk->nstripes) ? : 1;
|
||||||
|
chunk_stripe_length = grub_le_to_cpu64 (chunk->stripe_length) ? : 512;
|
||||||
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
||||||
"+0x%" PRIxGRUB_UINT64_T
|
"+0x%" PRIxGRUB_UINT64_T
|
||||||
" (%d stripes (%d substripes) of %"
|
" (%d stripes (%d substripes) of %"
|
||||||
PRIxGRUB_UINT64_T ")\n",
|
PRIxGRUB_UINT64_T ")\n",
|
||||||
grub_le_to_cpu64 (key->offset),
|
grub_le_to_cpu64 (key->offset),
|
||||||
grub_le_to_cpu64 (chunk->size),
|
grub_le_to_cpu64 (chunk->size),
|
||||||
grub_le_to_cpu16 (chunk->nstripes),
|
nstripes,
|
||||||
grub_le_to_cpu16 (chunk->nsubstripes),
|
grub_le_to_cpu16 (chunk->nsubstripes),
|
||||||
grub_le_to_cpu64 (chunk->stripe_length));
|
chunk_stripe_length);
|
||||||
|
|
||||||
switch (grub_le_to_cpu64 (chunk->type)
|
switch (grub_le_to_cpu64 (chunk->type)
|
||||||
& ~GRUB_BTRFS_CHUNK_TYPE_BITS_DONTCARE)
|
& ~GRUB_BTRFS_CHUNK_TYPE_BITS_DONTCARE)
|
||||||
|
@ -708,8 +712,10 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
||||||
grub_uint64_t stripe_length;
|
grub_uint64_t stripe_length;
|
||||||
grub_dprintf ("btrfs", "single\n");
|
grub_dprintf ("btrfs", "single\n");
|
||||||
stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size),
|
stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size),
|
||||||
grub_le_to_cpu16 (chunk->nstripes),
|
nstripes,
|
||||||
NULL);
|
NULL);
|
||||||
|
if (stripe_length == 0)
|
||||||
|
stripe_length = 512;
|
||||||
stripen = grub_divmod64 (off, stripe_length, &stripe_offset);
|
stripen = grub_divmod64 (off, stripe_length, &stripe_offset);
|
||||||
csize = (stripen + 1) * stripe_length - off;
|
csize = (stripen + 1) * stripe_length - off;
|
||||||
break;
|
break;
|
||||||
|
@ -730,33 +736,34 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
||||||
grub_uint64_t low;
|
grub_uint64_t low;
|
||||||
grub_dprintf ("btrfs", "RAID0\n");
|
grub_dprintf ("btrfs", "RAID0\n");
|
||||||
middle = grub_divmod64 (off,
|
middle = grub_divmod64 (off,
|
||||||
grub_le_to_cpu64 (chunk->stripe_length),
|
chunk_stripe_length,
|
||||||
&low);
|
&low);
|
||||||
|
|
||||||
high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes),
|
high = grub_divmod64 (middle, nstripes,
|
||||||
&stripen);
|
&stripen);
|
||||||
stripe_offset =
|
stripe_offset =
|
||||||
low + grub_le_to_cpu64 (chunk->stripe_length) * high;
|
low + chunk_stripe_length * high;
|
||||||
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
|
csize = chunk_stripe_length - low;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GRUB_BTRFS_CHUNK_TYPE_RAID10:
|
case GRUB_BTRFS_CHUNK_TYPE_RAID10:
|
||||||
{
|
{
|
||||||
grub_uint64_t middle, high;
|
grub_uint64_t middle, high;
|
||||||
grub_uint64_t low;
|
grub_uint64_t low;
|
||||||
|
grub_uint16_t nsubstripes;
|
||||||
|
nsubstripes = grub_le_to_cpu16 (chunk->nsubstripes) ? : 1;
|
||||||
middle = grub_divmod64 (off,
|
middle = grub_divmod64 (off,
|
||||||
grub_le_to_cpu64 (chunk->stripe_length),
|
chunk_stripe_length,
|
||||||
&low);
|
&low);
|
||||||
|
|
||||||
high = grub_divmod64 (middle,
|
high = grub_divmod64 (middle,
|
||||||
grub_le_to_cpu16 (chunk->nstripes)
|
nstripes / nsubstripes ? : 1,
|
||||||
/ grub_le_to_cpu16 (chunk->nsubstripes),
|
|
||||||
&stripen);
|
&stripen);
|
||||||
stripen *= grub_le_to_cpu16 (chunk->nsubstripes);
|
stripen *= nsubstripes;
|
||||||
redundancy = grub_le_to_cpu16 (chunk->nsubstripes);
|
redundancy = nsubstripes;
|
||||||
stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length)
|
stripe_offset = low + chunk_stripe_length
|
||||||
* high;
|
* high;
|
||||||
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
|
csize = chunk_stripe_length - low;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue