Fix zero-length memcpy from NULL found by UBSan #173
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:ubsan-fixes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
memcpy() with a NULL pointer is undefined even when the length is 0, and UBSan reports it as "null pointer passed as argument 2". Skip the copy when there is nothing to copy:
blockstore_flush.cpp): a zero-length small write has no checksums, soget_checksums()returns NULL when compaction merges them.list_objects()(blockstore_heap.cpp): the unstable or the tombstone list is NULL when only the other one is non-empty.immediate_commit != all(osd_primary_sync.cpp): a dirty PG without copies to delete after sync has an empty vector whosedata()is NULL, while another PG has some.ringloop_mock.cpp): an empty iovec of a write may have a NULLiov_base.Tested: built with
-DWITH_UBSAN=yes(GCC 13) and run withUBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1. On mastertest_pg_chaos --seed 18reports the flusher, list_objects and disk mock cases (withhalt_on_error=0; with=1it fails on the first), andtest_blockstoreandtest_heapfail on the list_objects one. With the fixtest_pg_chaos(100 seeds),test_blockstore,test_heap,test_blockstore_v1,test_blockstore_chaos,osd_testandosd_rmw_testpass with no reports. No existing test reaches the sync case: a scratchosd_testscenario (two dirty PGs, one with a misplaced object,immediate_commit=none, then SYNC) reportsosd_primary_sync.cpp:116on master and passes with the fix.Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA