Skip to content

Commit

Permalink
librbd: prevent creation of v2 image ids that are too large
Browse files Browse the repository at this point in the history
The librbd API is capped at 24 characters for expressing the
object prefix for data blocks (including trailing null byte).

Fixes: http://tracker.ceph.com/issues/16887
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 4de7c8d)
  • Loading branch information
Jason Dillaman authored and Vicente-Cheng committed Sep 5, 2016
1 parent eb27865 commit a531ae5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/librbd/internal.cc
Expand Up @@ -1029,6 +1029,14 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
extra = rand() % 0xFFFFFFFF;
bid_ss << std::hex << bid << std::hex << extra;
id = bid_ss.str();

// ensure the image id won't overflow the fixed block name size
const size_t max_id_length = RBD_MAX_BLOCK_NAME_SIZE -
strlen(RBD_DATA_PREFIX) - 1;
if (id.length() > max_id_length) {
id = id.substr(id.length() - max_id_length);
}

r = cls_client::set_id(&io_ctx, id_obj, id);
if (r < 0) {
lderr(cct) << "error setting image id: " << cpp_strerror(r) << dendl;
Expand Down

0 comments on commit a531ae5

Please sign in to comment.