Skip to content

Commit

Permalink
Fixed bug around reading MACAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Sep 15, 2023
1 parent efb47f8 commit 6cef117
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe

if (MACAddress != nullptr)
{
chip::CharSpan MACAddressSpan(MACAddress, strlen(MACAddress));
chip::CharSpan MACAddressSpan(MACAddress, strlen(MACAddress) - 1);
outTargetVideoPlayerInfo.SetMACAddress(MACAddressSpan);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta
jstring MACAddress = nullptr;
if (targetVideoPlayerInfo->GetMACAddress() != nullptr && targetVideoPlayerInfo->GetMACAddress()->data() != nullptr)
{
char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength + 1];
char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength + 1];
strncpy(MACAddressWithNil, targetVideoPlayerInfo->GetMACAddress()->data(),
targetVideoPlayerInfo->GetMACAddress()->size());
MACAddressWithNil[targetVideoPlayerInfo->GetMACAddress()->size()] = '\0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class TargetVideoPlayerInfo
uint16_t mPort;
chip::Inet::IPAddress mIpAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
chip::CharSpan mMACAddress;
char mMACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength];
char mMACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength];
chip::System::Clock::Timestamp mLastDiscovered;
bool mInitialized = false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ CHIP_ERROR PersistenceManager::WriteAllVideoPlayers(TargetVideoPlayerInfo videoP
tlvWriter.Put(TLV::ContextTag(kVideoPlayerLastDiscoveredTag), videoPlayer->GetLastDiscovered().count()));
if (videoPlayer->GetMACAddress() != nullptr && videoPlayer->GetMACAddress()->size() > 0)
{
ChipLogProgress(AppServer, "PersistenceManager::Write MAC Address Length %zu [%d]", videoPlayer->GetMACAddress()->size(), chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength);
ReturnErrorOnFailure(tlvWriter.PutBytes(TLV::ContextTag(kVideoPlayerMACAddressTag),
(const uint8_t *) videoPlayer->GetMACAddress()->data(),
static_cast<uint32_t>(videoPlayer->GetMACAddress()->size())));
Expand Down Expand Up @@ -227,7 +228,7 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide
size_t numIPs = 0;
Inet::IPAddress ipAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
uint64_t lastDiscoveredTicks = 0;
char MACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength] = {};
char MACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength] = {};
uint32_t MACAddressLength = 0;
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
uint16_t port = 0;
Expand Down Expand Up @@ -307,8 +308,9 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide
if (videoPlayersContainerTagNum == kVideoPlayerMACAddressTag)
{
MACAddressLength = reader.GetLength();
ChipLogProgress(AppServer, "PersistenceManager::Read MAC Address Length %u [%d]", MACAddressLength, chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength);
ReturnErrorOnFailure(reader.GetBytes(reinterpret_cast<uint8_t *>(MACAddressBuf),
2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength));
2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength));
continue;
}

Expand Down

0 comments on commit 6cef117

Please sign in to comment.