From d076c033e7fc9d5a5d4dacaab6a8d12b4000c1ab Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 21 Aug 2022 17:52:51 +0200 Subject: [PATCH] Avoid calling memcpy from empty string views ubsan is unhappy when passing a nullptr as the source pointer to memcpy even if the length is 0. Fixes #4720 --- src/shared_string.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shared_string.cc b/src/shared_string.cc index d76e0ac3..752ac828 100644 --- a/src/shared_string.cc +++ b/src/shared_string.cc @@ -16,6 +16,8 @@ StringDataPtr StringData::create(ArrayView strs) auto* data = reinterpret_cast(res + 1); for (auto& str : strs) { + if (str.length() == 0) // memccpy(..., nullptr, 0) is UB + continue; memcpy(data, str.begin(), (size_t)str.length()); data += (int)str.length(); }