struct rbd_image_header_ondisk *ondisk)
{
u32 snap_count;
+ size_t len;
size_t size;
memset(header, 0, sizeof (*header));
snap_count = le32_to_cpu(ondisk->snap_count);
- size = sizeof (ondisk->object_prefix) + 1;
- header->object_prefix = kmalloc(size, GFP_KERNEL);
+ len = strnlen(ondisk->object_prefix, sizeof (ondisk->object_prefix));
+ header->object_prefix = kmalloc(len + 1, GFP_KERNEL);
if (!header->object_prefix)
return -ENOMEM;
- memcpy(header->object_prefix, ondisk->object_prefix, size - 1);
- header->object_prefix[size - 1] = '\0';
+ memcpy(header->object_prefix, ondisk->object_prefix, len);
+ header->object_prefix[len] = '\0';
if (snap_count) {
header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);