Skip to content

Commit 2912561

Browse files
wgtdkprestyled-commits
authored andcommitted
[mdns] fix mDNS type length (#6771)
* [mdns] fix mDNS service type splitting * Restyled by clang-format Co-authored-by: Restyled.io <commits@restyled.io>
1 parent efdd23f commit 2912561

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/platform/Linux/MdnsImpl.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,16 @@ void MdnsAvahi::HandleBrowse(AvahiServiceBrowser * browser, AvahiIfIndex interfa
579579
if (strcmp("local", domain) == 0)
580580
{
581581
MdnsService service = {};
582+
char typeAndProtocol[kMdnsTypeAndProtocolMaxSize + 1];
582583

583584
strncpy(service.mName, name, sizeof(service.mName));
584-
strncpy(service.mType, type, sizeof(service.mType));
585585
service.mName[kMdnsNameMaxSize] = 0;
586+
strncpy(typeAndProtocol, type, sizeof(typeAndProtocol));
587+
typeAndProtocol[kMdnsTypeAndProtocolMaxSize] = 0;
588+
service.mProtocol = TruncateProtocolInType(typeAndProtocol);
589+
service.mAddressType = ToAddressType(protocol);
590+
strncpy(service.mType, typeAndProtocol, sizeof(service.mType));
586591
service.mType[kMdnsTypeMaxSize] = 0;
587-
service.mProtocol = TruncateProtocolInType(service.mType);
588-
service.mAddressType = ToAddressType(protocol);
589592
context->mServices.push_back(service);
590593
}
591594
break;
@@ -655,16 +658,19 @@ void MdnsAvahi::HandleResolve(AvahiServiceResolver * resolver, AvahiIfIndex inte
655658
break;
656659
case AVAHI_RESOLVER_FOUND:
657660
MdnsService result = {};
661+
char typeAndProtocol[kMdnsTypeAndProtocolMaxSize + 1];
658662

659663
result.mAddress.SetValue(chip::Inet::IPAddress());
660664
ChipLogError(DeviceLayer, "Avahi resolve found");
661665
strncpy(result.mName, name, sizeof(result.mName));
662-
strncpy(result.mType, type, sizeof(result.mType));
663666
result.mName[kMdnsNameMaxSize] = 0;
667+
strncpy(typeAndProtocol, type, sizeof(typeAndProtocol));
668+
typeAndProtocol[kMdnsTypeAndProtocolMaxSize] = 0;
669+
result.mProtocol = TruncateProtocolInType(typeAndProtocol);
670+
result.mPort = port;
671+
result.mAddressType = ToAddressType(protocol);
672+
strncpy(result.mType, typeAndProtocol, sizeof(result.mType));
664673
result.mType[kMdnsTypeMaxSize] = 0;
665-
result.mProtocol = TruncateProtocolInType(result.mType);
666-
result.mPort = port;
667-
result.mAddressType = ToAddressType(protocol);
668674

669675
if (address)
670676
{

0 commit comments

Comments
 (0)