diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index 7221a6d5ed6..7a1c9d36ef3 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -448,17 +448,18 @@ int get_pool_journal_names(const po::variables_map &vm, } } - if (pool_name->empty()) { + if (pool_name != nullptr && pool_name->empty()) { *pool_name = at::DEFAULT_POOL_NAME; } - if (journal_name != nullptr && journal_name->empty() && !image_name.empty()) { + if (pool_name != nullptr && journal_name != nullptr && + journal_name->empty() && !image_name.empty()) { // Try to get journal name from image info. librados::Rados rados; librados::IoCtx io_ctx; librbd::Image image; - int r = init_and_open_image(*pool_name, image_name, "", true, - &rados, &io_ctx, &image); + int r = init_and_open_image(*pool_name, image_name, "", true, &rados, + &io_ctx, &image); if (r < 0) { std::cerr << "rbd: failed to open image " << image_name << " to get journal name: " << cpp_strerror(r) << std::endl; diff --git a/src/tools/rbd/action/MergeDiff.cc b/src/tools/rbd/action/MergeDiff.cc index cdb593887b8..c28cb1d266c 100644 --- a/src/tools/rbd/action/MergeDiff.cc +++ b/src/tools/rbd/action/MergeDiff.cc @@ -160,7 +160,9 @@ static int do_merge_diff(const char *first, const char *second, string f_from, f_to; string s_from, s_to; - uint64_t f_size, s_size, pc_size; + uint64_t f_size = 0; + uint64_t s_size = 0; + uint64_t pc_size; __u8 f_tag = 0, s_tag = 0; uint64_t f_off = 0, f_len = 0; @@ -199,7 +201,6 @@ static int do_merge_diff(const char *first, const char *second, //We just handle the case like 'banner, [ftag], [ttag], stag, [wztag]*,etag', // and the (offset,length) in wztag must be ascending order. - r = parse_diff_header(fd, &f_tag, &f_from, &f_to, &f_size); if (r < 0) { std::cerr << "rbd: failed to parse first diff header" << std::endl; @@ -323,6 +324,10 @@ static int do_merge_diff(const char *first, const char *second, if (delta > f_len) delta = f_len; r = accept_diff_body(fd, pd, f_tag, f_off, delta); + if (r < 0) { + std::cerr << "rbd: failed to merge diff chunk" << std::endl; + goto done; + } f_off += delta; f_len -= delta; @@ -361,11 +366,16 @@ static int do_merge_diff(const char *first, const char *second, assert(f_off >= s_off + s_len); if (s_len) { r = accept_diff_body(sd, pd, s_tag, s_off, s_len); + if (r < 0) { + std::cerr << "rbd: failed to merge diff chunk" << std::endl; + goto done; + } s_off += s_len; s_len = 0; s_tag = 0; - } else + } else { assert(f_end && s_end); + } continue; } diff --git a/src/tools/rbd/action/Snap.cc b/src/tools/rbd/action/Snap.cc index 892d051d8c3..9107954a039 100644 --- a/src/tools/rbd/action/Snap.cc +++ b/src/tools/rbd/action/Snap.cc @@ -470,6 +470,9 @@ int execute_set_limit(const po::variables_map &vm) { int r = utils::get_pool_image_snapshot_names( vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name, &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_NONE); + if (r < 0) { + return r; + } if (vm.count(at::LIMIT)) { limit = vm[at::LIMIT].as(); @@ -509,6 +512,9 @@ int execute_clear_limit(const po::variables_map &vm) { int r = utils::get_pool_image_snapshot_names( vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name, &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_NONE); + if (r < 0) { + return r; + } librados::Rados rados; librados::IoCtx io_ctx; diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 526bd5120f0..6e24a1e1b1d 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -283,6 +283,7 @@ private: break; default: derr << *pctx << ": invalid request command" << dendl; + c->release(); return; } }