]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/buffer: do not deref _raw ptr when checking for hypercombind buf
authorKefu Chai <kchai@redhat.com>
Sat, 5 Sep 2020 13:10:48 +0000 (21:10 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 7 Sep 2020 15:22:43 +0000 (23:22 +0800)
_raw could be null when the buffer::ptr is std::moved away. and ASan
complains when we try to dereference a nullptr. so use a little awkward
way to calculate the address instead

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/buffer.cc

index ee2bdc1e9e280813f2e305350fad7df6f749702e..b71af2ec75e9e0d678bb35fe718bcf9ce3e724ad 100644 (file)
@@ -2150,13 +2150,19 @@ buffer::list buffer::list::static_from_string(string& s) {
 bool buffer::ptr_node::dispose_if_hypercombined(
   buffer::ptr_node* const delete_this)
 {
-  const bool is_hypercombined = static_cast<void*>(delete_this) == \
-    static_cast<void*>(&delete_this->_raw->bptr_storage);
+  // in case _raw is nullptr
+  const std::uintptr_t bptr =
+    (reinterpret_cast<std::uintptr_t>(delete_this->_raw) +
+     offsetof(buffer::raw, bptr_storage));
+  const bool is_hypercombined =
+    reinterpret_cast<std::uintptr_t>(delete_this) == bptr;
   if (is_hypercombined) {
     ceph_assert_always("hypercombining is currently disabled" == nullptr);
     delete_this->~ptr_node();
+    return true;
+  } else {
+    return false;
   }
-  return is_hypercombined;
 }
 
 std::unique_ptr<buffer::ptr_node, buffer::ptr_node::disposer>