]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: does not crash if image header is too short 9044/head
authorKefu Chai <kchai@redhat.com>
Wed, 27 Apr 2016 16:59:34 +0000 (00:59 +0800)
committerJason Dillaman <dillaman@redhat.com>
Tue, 10 May 2016 16:27:53 +0000 (12:27 -0400)
if something goes wrong with the object, and returns a chunk shorter
than expected, don't panic

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 7b52183addda83f98c8b1f37d3de20ca0fc4687b)

src/librbd/internal.cc

index 5276052c5190fd18f9031b27809082663c764625..dab665147c4f03b6282640617e0856df894ecfe9 100644 (file)
@@ -523,7 +523,8 @@ remove_mirroring_image:
       off += r;
     } while (r == READ_SIZE);
 
-    if (memcmp(RBD_HEADER_TEXT, header.c_str(), sizeof(RBD_HEADER_TEXT))) {
+    if (header.length() < sizeof(RBD_HEADER_TEXT) ||
+       memcmp(RBD_HEADER_TEXT, header.c_str(), sizeof(RBD_HEADER_TEXT))) {
       CephContext *cct = (CephContext *)io_ctx.cct();
       lderr(cct) << "unrecognized header format" << dendl;
       return -ENXIO;