]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: prevent creation of v2 image ids that are too large 10652/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 5 Aug 2016 00:40:10 +0000 (20:40 -0400)
committerLoic Dachary <ldachary@redhat.com>
Wed, 10 Aug 2016 08:49:11 +0000 (10:49 +0200)
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 4de7c8d0a7222c83268d03b99015c6b9d25f124d)

src/librbd/internal.cc

index d3f1cd3fb714f67a79843cadd9fbbbfd1a358729..9e1112c72c73edf201ecafcaa1af17e9fe972eef 100644 (file)
@@ -1048,6 +1048,14 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force,
     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;