From cd07de219f794a857ee287260d35b1956a56870e Mon Sep 17 00:00:00 2001 From: cecille Date: Mon, 2 Oct 2023 13:34:21 -0400 Subject: [PATCH 1/3] CastingDiscovery: fix snprintf warning snprintf appends a null terminator, as does strcat, so both buffers need to be upsized by 1 to accommodate that. --- examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h | 2 +- .../tv-casting-common/core/CastingPlayerDiscovery.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h index c523fb111b0b48..3f33b69e526c0e 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h @@ -45,7 +45,7 @@ const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength; class CastingPlayerAttributes { public: - char id[kIdMaxLength] = {}; + char id[kIdMaxLength + 1] = {}; char deviceName[chip::Dnssd::kMaxDeviceNameLen + 1] = {}; char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {}; char instanceName[chip::Dnssd::kHostNameMaxLength + 1] = {}; diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp index 65a589932c1a4b..e391116c0ef1f7 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayerDiscovery.cpp @@ -81,7 +81,7 @@ void DeviceDiscoveryDelegateImpl::OnDiscoveredDevice(const chip::Dnssd::Discover CastingPlayerAttributes attributes; strcpy(attributes.id, nodeData.resolutionData.hostName); - char port[kPortMaxLength] = {}; + char port[kPortMaxLength + 1] = {}; snprintf(port, sizeof(port), "%u", nodeData.resolutionData.port); strcat(attributes.id, port); From 18e9e4358708aa43e8544465f291105dfe3ccfb6 Mon Sep 17 00:00:00 2001 From: cecille Date: Mon, 2 Oct 2023 17:03:39 -0400 Subject: [PATCH 2/3] ID buffer size was also incorrect --- examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h index 3f33b69e526c0e..bfa048e8984651 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h @@ -40,7 +40,8 @@ using ConnectCallback = std::function; using DisconnectCallback = std::function; const int kPortMaxLength = 5; // port is uint16_t -const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength; +// +1 for the : between the hostname and the port. +const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength + 1; class CastingPlayerAttributes { From ba11a26abab3d32b91fff91555055ef9f8f865ff Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 2 Oct 2023 21:04:33 +0000 Subject: [PATCH 3/3] Restyled by clang-format --- examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h index bfa048e8984651..977642790e60e6 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h @@ -41,7 +41,7 @@ using DisconnectCallback = std::function; const int kPortMaxLength = 5; // port is uint16_t // +1 for the : between the hostname and the port. -const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength + 1; +const int kIdMaxLength = chip::Dnssd::kHostNameMaxLength + kPortMaxLength + 1; class CastingPlayerAttributes {