Skip to content

Commit

Permalink
Right sizing MACAddress buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Oct 17, 2023
1 parent 9544d43 commit f426749
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe
jfieldID getInstanceNameField = env->GetFieldID(jVideoPlayerClass, "instanceName", "Ljava/lang/String;");
jstring jInstanceName = static_cast<jstring>(env->GetObjectField(videoPlayer, getInstanceNameField));
const char * instanceName = {};
if(jInstanceName != nullptr)
if (jInstanceName != nullptr)
{
instanceName = env->GetStringUTFChars(jInstanceName, 0);
}
Expand All @@ -182,7 +182,7 @@ CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, Targe

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

Expand Down Expand Up @@ -256,9 +256,9 @@ CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * ta
jstring MACAddress = nullptr;
if (targetVideoPlayerInfo->GetMACAddress() != nullptr && targetVideoPlayerInfo->GetMACAddress()->data() != nullptr)
{
char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength + 1];
strncpy(MACAddressWithNil, targetVideoPlayerInfo->GetMACAddress()->data(),
targetVideoPlayerInfo->GetMACAddress()->size());
char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength + 1];
memcpy(MACAddressWithNil, targetVideoPlayerInfo->GetMACAddress()->data(),
targetVideoPlayerInfo->GetMACAddress()->size());
MACAddressWithNil[targetVideoPlayerInfo->GetMACAddress()->size()] = '\0';
MACAddress = env->NewStringUTF(MACAddressWithNil);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class TargetVideoPlayerInfo
char mInstanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1];
uint16_t mPort;
chip::CharSpan mMACAddress;
char mMACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength];
char mMACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength];
chip::System::Clock::Timestamp mLastDiscovered;
bool mIsAsleep = false;
bool mInitialized = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide
char hostName[chip::Dnssd::kHostNameMaxLength + 1] = {};
size_t numIPs = 0;
Inet::IPAddress ipAddress[chip::Dnssd::CommonResolutionData::kMaxIPAddresses];
uint64_t lastDiscoveredMs = 0;
char MACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength] = {};
uint32_t MACAddressLength = 0;
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
uint16_t port = 0;
uint64_t lastDiscoveredMs = 0;
char MACAddressBuf[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength] = {};
uint32_t MACAddressLength = 0;
char instanceName[chip::Dnssd::Commission::kInstanceNameMaxLength + 1] = {};
uint16_t port = 0;

CHIP_ERROR err;
while ((err = reader.Next()) == CHIP_NO_ERROR)
Expand Down Expand Up @@ -349,7 +349,7 @@ CHIP_ERROR PersistenceManager::ReadAllVideoPlayers(TargetVideoPlayerInfo outVide
{
MACAddressLength = reader.GetLength();
ReturnErrorOnFailure(reader.GetBytes(reinterpret_cast<uint8_t *>(MACAddressBuf),
2 * chip::DeviceLayer::ConfigurationManager::kMaxMACAddressLength));
2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength));
continue;
}

Expand Down

0 comments on commit f426749

Please sign in to comment.