From 7af1dc1d27159b072ee941f9ae42d48df004962b Mon Sep 17 00:00:00 2001 From: Paul Dreik Date: Sat, 21 Aug 2021 14:24:30 +0200 Subject: [PATCH] fix UB in fuzzer common (memcpy on nullptr) --- test/fuzzing/fuzzer-common.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/fuzzing/fuzzer-common.h b/test/fuzzing/fuzzer-common.h index e2e01409..c0a24672 100644 --- a/test/fuzzing/fuzzer-common.h +++ b/test/fuzzing/fuzzer-common.h @@ -56,7 +56,9 @@ struct data_to_string { data_to_string(const uint8_t* data, size_t size, bool add_terminator = false) : buffer(size + (add_terminator ? 1 : 0)) { - std::memcpy(buffer.data(), data, size); + if (size) { + std::memcpy(buffer.data(), data, size); + } } fmt::string_view get() const { return {buffer.data(), buffer.size()}; }