From 50a9c88bb34aa59b10d053f685bec36da655fd60 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 17 Nov 2021 14:28:40 -0500 Subject: [PATCH] Validate value lenght - 0 size value should not copy anything --- src/platform/Darwin/DnssdImpl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 });