rbd.cc: tolerate lack of NUL-termination on block_name_prefix

Fixes: #7577
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Dan Mick 2014-03-25 17:09:48 -07:00 committed by Sage Weil
parent fab374b039
commit fd76fec589

View File

@ -521,6 +521,9 @@ static int do_show_info(const char *imgname, librbd::Image& image,
f->dump_string("block_name_prefix", info.block_name_prefix);
f->dump_int("format", (old_format ? 1 : 2));
} else {
char prefix[RBD_MAX_BLOCK_NAME_SIZE + 1];
strncpy(prefix, info.block_name_prefix, RBD_MAX_BLOCK_NAME_SIZE);
prefix[RBD_MAX_BLOCK_NAME_SIZE] = '\0';
cout << "rbd image '" << imgname << "':\n"
<< "\tsize " << prettybyte_t(info.size) << " in "
<< info.num_objs << " objects"
@ -528,7 +531,7 @@ static int do_show_info(const char *imgname, librbd::Image& image,
<< "\torder " << info.order
<< " (" << prettybyte_t(info.obj_size) << " objects)"
<< std::endl
<< "\tblock_name_prefix: " << info.block_name_prefix
<< "\tblock_name_prefix: " << prefix
<< std::endl
<< "\tformat: " << (old_format ? "1" : "2")
<< std::endl;