Fix zero-length memcpy from NULL found by UBSan #173

Merged
vitalif merged 1 commits from koolkhel/vitastor:ubsan-fixes into master 2026-11-25 20:53:12 +03:00

1 Commits

Author SHA1 Message Date
e529f7bcf3 Fix zero-length memcpy from NULL found by UBSan
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:

- Store v2 flusher: a zero-length small write has no checksums, so
  get_checksums() returns NULL when compaction merges them
- Store v2 list_objects(): the unstable or the tombstone list is NULL
  when only the other one is non-empty
- OSD sync with immediate_commit != all: a dirty PG without copies to
  delete after sync has an empty vector whose data() is NULL, while
  another PG has some
- disk mock: an empty iovec of a write may have a NULL iov_base

Found by test_pg_chaos --seed 18, test_blockstore and test_heap built
with WITH_UBSAN=yes.
2026-11-24 11:52:14 +03:00