diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index 389ed082a73fe4..81c5aa2b3c261e 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -434,8 +434,9 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin // Truncation, but nothing better we can do valueLen = sizeof(value) - 1; } - - memcpy(value, valuePtr, valueLen - 1); + if (valueLen > 1) { + memcpy(value, valuePtr, valueLen - 1); + } value[valueLen] = 0; sdCtx->textEntries.push_back(TextEntry{ strdup(key), reinterpret_cast(strdup(value)), valueLen });