]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: correct coverity warnings 12954/head
authorJason Dillaman <dillaman@redhat.com>
Tue, 17 Jan 2017 03:44:04 +0000 (22:44 -0500)
committerJason Dillaman <dillaman@redhat.com>
Tue, 17 Jan 2017 03:44:04 +0000 (22:44 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd/Utils.cc
src/tools/rbd/action/MergeDiff.cc
src/tools/rbd/action/Snap.cc
src/tools/rbd_nbd/rbd-nbd.cc

index 7221a6d5ed60acc724110ca2ff97cfa9a4b9c077..7a1c9d36ef38728ae96942a4d1851e4db07fbd4c 100644 (file)
@@ -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;
index cdb593887b8972bade87002dc2c18834da6208dc..c28cb1d266ccf37165294a4da7617e7bd892c4b9 100644 (file)
@@ -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;
   }
 
index 892d051d8c343474b5d6b0b2798692106e72d2d3..9107954a039422aa5a86c5aac11625808ae25e19 100644 (file)
@@ -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<uint64_t>();
@@ -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;
index 526bd5120f0cae98f5797a50e0182df9ed25caa8..6e24a1e1b1d6f457e8cebd5b1a2283a37a6f9ac6 100644 (file)
@@ -283,6 +283,7 @@ private:
           break;
         default:
          derr << *pctx << ": invalid request command" << dendl;
+          c->release();
           return;
       }
     }