]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add coverity annotations and asserts for null dereferences 52473/head
authorVedansh Bhartia <vedanshbhartia@gmail.com>
Thu, 6 Jul 2023 05:57:43 +0000 (11:27 +0530)
committerVedansh Bhartia <vedanshbhartia@gmail.com>
Sun, 16 Jul 2023 16:05:46 +0000 (21:35 +0530)
Signed-off-by: Vedansh Bhartia <vedanshbhartia@gmail.com>
src/rgw/driver/rados/rgw_d3n_datacache.h
src/rgw/driver/rados/rgw_rados.cc
src/rgw/driver/rados/rgw_sync.cc
src/rgw/rgw_file.cc
src/rgw/rgw_kmip_client_impl.cc
src/rgw/rgw_op.cc

index 668e224e85b94fb9ea1a7607f546f5894783c4a1..196f892329f8ca1ee5cdce58ccca97efda32bfeb 100644 (file)
@@ -177,6 +177,8 @@ int D3nRGWDataCache<T>::get_obj_iterate_cb(const DoutPrefixProvider *dpp, const
     if (r < 0)
       return r;
 
+    // astate can be modified by append_atomic_test
+    // coverity[check_after_deref:SUPPRESS]
     if (astate &&
         obj_ofs < astate->data.length()) {
       unsigned chunk_len = std::min((uint64_t)astate->data.length() - obj_ofs, (uint64_t)len);
index 2a213cafc6e03ff6b685a2409811ffb89121d649..20eda066aa3e7009c71cc5646215c91a0a3848c0 100644 (file)
@@ -6491,6 +6491,8 @@ int RGWRados::Object::Read::read(int64_t ofs, int64_t end,
     if (r < 0)
       return r;
 
+    // astate can be modified by append_atomic_test
+    // coverity[check_after_deref:SUPPRESS]
     if (astate && astate->prefetch_data) {
       if (!ofs && astate->data.length() >= len) {
         bl = astate->data;
@@ -6606,6 +6608,8 @@ int RGWRados::get_obj_iterate_cb(const DoutPrefixProvider *dpp,
     if (r < 0)
       return r;
 
+    // astate can be modified by append_atomic_test
+    // coverity[check_after_deref:SUPPRESS]
     if (astate &&
         obj_ofs < astate->data.length()) {
       unsigned chunk_len = std::min((uint64_t)astate->data.length() - obj_ofs, (uint64_t)len);
index 262e00ba9dc20634c854c1673a92403e9a6f74a6..c7634d07bbd6c9dafcd1cfa075da0f4b27a041ef 100644 (file)
@@ -81,13 +81,14 @@ int RGWBackoffControlCR::operate(const DoutPrefixProvider *dpp) {
     // retry the operation until it succeeds
     while (true) {
       yield {
-       std::lock_guard l{lock};
+        std::lock_guard l{lock};
         cr = alloc_cr();
         cr->get();
         call(cr);
       }
       {
-       std::lock_guard l{lock};
+        std::lock_guard l{lock};
+        // coverity[var_deref_model:SUPPRESS]
         cr->put();
         cr = NULL;
       }
index ee32170a116187ddc4490ab7f2ad93c3c32085a2..dbf85f491f559d6e31c5ff70fb896c6003f1b139 100644 (file)
@@ -383,6 +383,7 @@ namespace rgw {
        /* implies !rgw_fh, so also !LOCKED */
        return -ENOENT;
       }
+      assert(rgw_fh);
 
       if (bs.num_entries > 1) {
        unref(bkt_fh); /* return stat_bucket ref */
@@ -449,6 +450,7 @@ namespace rgw {
 
     /* ENOENT when raced with other s3 gateway */
     if (! rc || rc == -ENOENT) {
+      // coverity[var_deref_op:SUPPRESS]
       rgw_fh->flags |= RGWFileHandle::FLAG_DELETED;
       fh_cache.remove(rgw_fh->fh.fh_hk.object, rgw_fh,
                      RGWFileHandle::FHCache::FLAG_LOCK);
index b7f4f38e620d9d600a65b26fec8d714982ee71b0..e83a62e1507fd8810c5ee4b18bae5279e99e08d0 100644 (file)
@@ -243,11 +243,7 @@ RGWKmipHandleBuilder::build() const
 
   failed = 0;
 Done:
-  if (!failed)
-    ;
-  else if (!r)
-    ;
-  else {
+  if(failed && r) {
     kmip_free_handle_stuff(r);
     delete r;
     r = 0;
index 77adef88c748d0b0e176c815541508ea8194ab1b..b9f7d2d4cc6bb48164a75402b5905b7896614bdc 100644 (file)
@@ -4292,7 +4292,10 @@ void RGWPutObj::execute(optional_yield y)
 
   if (compressor && compressor->is_compressed()) {
     bufferlist tmp;
-    RGWCompressionInfo cs_info;
+    RGWCompressionInfo cs_info;      
+    assert(plugin != nullptr);  
+    // plugin exists when the compressor does
+    // coverity[dereference:SUPPRESS]
     cs_info.compression_type = plugin->get_type_name();
     cs_info.orig_size = s->obj_size;
     cs_info.compressor_message = compressor->get_compressor_message();
@@ -4632,6 +4635,9 @@ void RGWPostObj::execute(optional_yield y)
     if (compressor && compressor->is_compressed()) {
       ceph::bufferlist tmp;
       RGWCompressionInfo cs_info;
+      assert(plugin != nullptr);
+      // plugin exists when the compressor does
+      // coverity[dereference:SUPPRESS]
       cs_info.compression_type = plugin->get_type_name();
       cs_info.orig_size = s->obj_size;
       cs_info.compressor_message = compressor->get_compressor_message();
@@ -7757,6 +7763,9 @@ int RGWBulkUploadOp::handle_file(const std::string_view path,
   if (compressor && compressor->is_compressed()) {
     ceph::bufferlist tmp;
     RGWCompressionInfo cs_info;
+    assert(plugin != nullptr);
+    // plugin exists when the compressor does
+    // coverity[dereference:SUPPRESS]
     cs_info.compression_type = plugin->get_type_name();
     cs_info.orig_size = size;
     cs_info.compressor_message = compressor->get_compressor_message();