From 11760202850e310234381e2dcb93f7696e85b660 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 29 May 2023 13:30:05 -0400 Subject: [PATCH] Fix thread names for k32w's DiagnosticDataProvider. (#26892) The old code was copying in N-1 chars, then creating a string of length N from them, so ending up with a random byte in the string, which could lead to the string not being valid UTF-8. Fixes https://github.com/project-chip/connectedhomeip/issues/26891 --- src/platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.cpp b/src/platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.cpp index 5d0f48b010680a..34ef40e47b1351 100644 --- a/src/platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.cpp @@ -110,8 +110,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadM { ThreadMetrics * thread = (ThreadMetrics *) pvPortMalloc(sizeof(ThreadMetrics)); - strncpy(thread->NameBuf, taskStatusArray[x].pcTaskName, kMaxThreadNameLength - 1); - thread->NameBuf[kMaxThreadNameLength] = '\0'; + Platform::CopyString(thread->NameBuf, taskStatusArray[x].pcTaskName); thread->name.Emplace(CharSpan::fromCharString(thread->NameBuf)); thread->id = taskStatusArray[x].xTaskNumber;