Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320382
b: refs/heads/master
c: ccece23
h: refs/heads/master
v: v3
  • Loading branch information
Alex Elder authored and Sage Weil committed Jul 31, 2012
1 parent fdcd9ec commit b9fd290
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 913d2fdcf60576cbbd82969fcb2bc78a4d59ba33
refs/heads/master: ccece235d3737221e7a1118fdbd8474112adac84
18 changes: 13 additions & 5 deletions trunk/drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,23 +494,23 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
struct rbd_image_header_ondisk *ondisk,
u32 allocated_snaps)
{
u32 i, snap_count;
u32 snap_count;

if (!rbd_dev_ondisk_valid(ondisk))
return -ENXIO;

snap_count = le32_to_cpu(ondisk->snap_count);
if (snap_count > (UINT_MAX - sizeof(struct ceph_snap_context))
/ sizeof (*ondisk))
if (snap_count > (SIZE_MAX - sizeof(struct ceph_snap_context))
/ sizeof (u64))
return -EINVAL;
header->snapc = kmalloc(sizeof(struct ceph_snap_context) +
snap_count * sizeof(u64),
GFP_KERNEL);
if (!header->snapc)
return -ENOMEM;

header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
if (snap_count) {
header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
header->snap_names = kmalloc(header->snap_names_len,
GFP_KERNEL);
if (!header->snap_names)
Expand All @@ -520,6 +520,8 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
if (!header->snap_sizes)
goto err_names;
} else {
WARN_ON(ondisk->snap_names_len);
header->snap_names_len = 0;
header->snap_names = NULL;
header->snap_sizes = NULL;
}
Expand All @@ -544,6 +546,8 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
header->total_snaps = snap_count;

if (snap_count && allocated_snaps == snap_count) {
int i;

for (i = 0; i < snap_count; i++) {
header->snapc->snaps[i] =
le64_to_cpu(ondisk->snaps[i].id);
Expand All @@ -552,18 +556,22 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
}

/* copy snapshot names */
memcpy(header->snap_names, &ondisk->snaps[i],
memcpy(header->snap_names, &ondisk->snaps[snap_count],
header->snap_names_len);
}

return 0;

err_sizes:
kfree(header->snap_sizes);
header->snap_sizes = NULL;
err_names:
kfree(header->snap_names);
header->snap_names = NULL;
err_snapc:
kfree(header->snapc);
header->snapc = NULL;

return -ENOMEM;
}

Expand Down

0 comments on commit b9fd290

Please sign in to comment.