Skip to content

Commit

Permalink
[mdns] fix mDNS type length
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed May 13, 2021
1 parent 4bfdd42 commit 1d6a6fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/lib/mdns/platform/Mdns.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
namespace chip {
namespace Mdns {

static constexpr uint8_t kMdnsNameMaxSize = 33; // [Node]-[Fabric] ID in hex - 16+1+16
static constexpr uint8_t kMdnsProtocolTextMaxSize = 4; // "_tcp" or "_udp"
static constexpr uint8_t kMdnsTypeMaxSize = 6; // "_chip", "_chipc" or "_chipd"
static constexpr uint8_t kMdnsTypeAndProtocolMaxSize = kMdnsTypeMaxSize + kMdnsProtocolTextMaxSize + 1; // <type>.<protocol>
static constexpr uint16_t kMdnsTextMaxSize = 64;
static constexpr uint8_t kMdnsNameMaxSize = 33; // [Node]-[Fabric] ID in hex - 16+1+16
static constexpr uint8_t kMdnsProtocolTextMaxSize = 4; // "_tcp" or "_udp"
static constexpr uint8_t kMdnsTypeMaxSize = 6 + kMdnsProtocolTextMaxSize + 1; // <"_chip", "_chipc" or "_chipd">.<protocol>
static constexpr uint16_t kMdnsTextMaxSize = 64;

enum class MdnsServiceProtocol : uint8_t
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class GenericThreadStackManagerImpl_OpenThread
{
static constexpr uint8_t kMaxServicesNumber = CHIP_DEVICE_CONFIG_THREAD_SRP_MAX_SERVICES;
static constexpr uint8_t kMaxInstanceNameSize = chip::Mdns::kMdnsNameMaxSize;
static constexpr uint8_t kMaxNameSize = chip::Mdns::kMdnsTypeAndProtocolMaxSize;
static constexpr uint8_t kMaxNameSize = chip::Mdns::kMdnsTypeMaxSize;
static constexpr uint8_t kMaxHostNameSize = 16;
// Thread only supports operational discovery
static constexpr uint8_t kMaxTxtEntriesNumber = chip::Mdns::OperationalAdvertisingParameters::kNumAdvertisingTxtEntries;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/OpenThread/MdnsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CHIP_ERROR ChipMdnsPublishService(const MdnsService * service)

VerifyOrExit(service, result = CHIP_ERROR_INVALID_ARGUMENT);

char serviceType[chip::Mdns::kMdnsTypeAndProtocolMaxSize + 1];
char serviceType[chip::Mdns::kMdnsTypeMaxSize + 1];
snprintf(serviceType, sizeof(serviceType), "%s.%s", service->mType, GetProtocolString(service->mProtocol));

// Try to remove service before adding it, as SRP doesn't allow to update existing services.
Expand All @@ -74,7 +74,7 @@ CHIP_ERROR ChipMdnsStopPublishService(const MdnsService * service)
if (service == nullptr)
return CHIP_ERROR_INVALID_ARGUMENT;

char serviceType[chip::Mdns::kMdnsTypeAndProtocolMaxSize + 1];
char serviceType[chip::Mdns::kMdnsTypeMaxSize + 1];
snprintf(serviceType, sizeof(serviceType), "%s.%s", service->mType, GetProtocolString(service->mProtocol));

return ThreadStackMgr().RemoveSrpService(service->mName, serviceType);
Expand Down

0 comments on commit 1d6a6fb

Please sign in to comment.