From 2cc091fcddb3bfe04ce2609bb3b043dee852e1e4 Mon Sep 17 00:00:00 2001 From: kangping Date: Mon, 10 May 2021 21:48:43 +0800 Subject: [PATCH] [dns-sd] fix SRP service name length --- src/app/server/Mdns.cpp | 2 +- .../GenericThreadStackManagerImpl_OpenThread.cpp | 12 +++++++----- .../GenericThreadStackManagerImpl_OpenThread.h | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/server/Mdns.cpp b/src/app/server/Mdns.cpp index 5af680afaf9726..8827d28a134c59 100644 --- a/src/app/server/Mdns.cpp +++ b/src/app/server/Mdns.cpp @@ -107,7 +107,7 @@ CHIP_ERROR AdvertiseOperational() auto & mdnsAdvertiser = chip::Mdns::ServiceAdvertiser::Instance(); - ChipLogProgress(Discovery, "Advertise operational node 0x%08" PRIx32 "%08" PRIx32 "-0x%08" PRIx32 "%08" PRIx32, + ChipLogProgress(Discovery, "Advertise operational node %08" PRIx32 "%08" PRIx32 "-%08" PRIx32 "%08" PRIx32, static_cast(advertiseParameters.GetPeerId().GetFabricId() >> 32), static_cast(advertiseParameters.GetPeerId().GetFabricId()), static_cast(advertiseParameters.GetPeerId().GetNodeId() >> 32), diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index 6635494ca67bee..dbffd5de4a5186 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -1074,9 +1074,9 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_AddSrpService(c Impl()->LockThreadStack(); VerifyOrExit(aInstanceName, error = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(strlen(aInstanceName) < SrpClient::kMaxInstanceNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(strlen(aInstanceName) <= SrpClient::kMaxInstanceNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); VerifyOrExit(aName, error = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(strlen(aName) < SrpClient::kMaxNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(strlen(aName) <= SrpClient::kMaxNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); // Check if service with desired instance name already exists and try to find empty slot in array for new service for (typename SrpClient::Service & service : mSrpClient.mServices) @@ -1130,6 +1130,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_AddSrpService(c srpService->mService.mTxtEntries = srpService->mTxtEntries; } + ChipLogError(Discovery, "advertising srp service: %s.%s", srpService->mService.mInstanceName, srpService->mService.mName); error = MapOpenThreadError(otSrpClientAddService(mOTInst, &(srpService->mService))); exit: @@ -1147,9 +1148,9 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_RemoveSrpServic Impl()->LockThreadStack(); VerifyOrExit(aInstanceName, error = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(strlen(aInstanceName) < SrpClient::kMaxInstanceNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(strlen(aInstanceName) <= SrpClient::kMaxInstanceNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); VerifyOrExit(aName, error = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(strlen(aName) < SrpClient::kMaxNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(strlen(aName) <= SrpClient::kMaxNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); // Check if service to remove exists. for (typename SrpClient::Service & service : mSrpClient.mServices) @@ -1163,6 +1164,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_RemoveSrpServic VerifyOrExit(srpService, error = MapOpenThreadError(OT_ERROR_NOT_FOUND)); + ChipLogError(Discovery, "removing srp service: %s.%s", aInstanceName, aName); error = MapOpenThreadError(otSrpClientRemoveService(mOTInst, &(srpService->mService))); exit: @@ -1199,7 +1201,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetupSrpHost(co Impl()->LockThreadStack(); VerifyOrExit(aHostName, error = CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrExit(strlen(aHostName) < SrpClient::kMaxHostNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); + VerifyOrExit(strlen(aHostName) <= SrpClient::kMaxHostNameSize, error = CHIP_ERROR_INVALID_STRING_LENGTH); // Avoid adding the same host name multiple times if (strcmp(mSrpClient.mHostName, aHostName) != 0) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h index 71ca8d9ff65540..0435cb1e52ea94 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h @@ -131,14 +131,14 @@ class GenericThreadStackManagerImpl_OpenThread struct Service { otSrpClientService mService; - char mInstanceName[kMaxInstanceNameSize]; - char mName[kMaxNameSize]; + char mInstanceName[kMaxInstanceNameSize + 1]; + char mName[kMaxNameSize + 1]; otDnsTxtEntry mTxtEntries[kMaxTxtEntriesNumber]; uint8_t mTxtValueBuffers[kMaxTxtEntriesNumber][kMaxTxtValueSize]; char mTxtKeyBuffers[kMaxTxtEntriesNumber][kMaxTxtKeySize]; }; - char mHostName[kMaxHostNameSize]; + char mHostName[kMaxHostNameSize + 1]; otIp6Address mHostAddress; Service mServices[kMaxServicesNumber]; };