[mac] fix the Mac::NetworkName length check (length >= 1) (#7018)

This commit fixes the `NetworkName` check (for its length to be larger
than zero) which was recently added in commit e2f0afab5d. This commit
moves the name length check to method `Set(const NameData &aNameData)`
and after the `newLen` is calculated.

This commit also updates `TestMacNetworkName()` in unit test to verify
that setting the network name to an empty string correctly fails with
`kErrorInvalidArgs`.
This commit is contained in:
Abtin Keshavarzian
2021-09-22 11:05:27 -07:00
committed by GitHub
parent 6153855ae0
commit 3c14f7b30f
2 changed files with 3 additions and 6 deletions
+2 -4
View File
@@ -190,8 +190,7 @@ void TestMacNetworkName(void)
SuccessOrQuit(networkName.Set(Mac::NameData(kName2, sizeof(kName2))));
CompareNetworkName(networkName, kName2);
SuccessOrQuit(networkName.Set(Mac::NameData(kEmptyName, 0)));
CompareNetworkName(networkName, kEmptyName);
VerifyOrQuit(networkName.Set(Mac::NameData(kEmptyName, 0)) == kErrorInvalidArgs);
SuccessOrQuit(networkName.Set(Mac::NameData(kLongName, sizeof(kLongName))));
CompareNetworkName(networkName, kLongName);
@@ -199,8 +198,7 @@ void TestMacNetworkName(void)
VerifyOrQuit(networkName.Set(Mac::NameData(kLongName, sizeof(kLongName) - 1)) == kErrorAlready,
"failed to detect duplicate");
SuccessOrQuit(networkName.Set(Mac::NameData(nullptr, 0)));
CompareNetworkName(networkName, kEmptyName);
VerifyOrQuit(networkName.Set(kEmptyName) == kErrorInvalidArgs);
SuccessOrQuit(networkName.Set(Mac::NameData(kName1, sizeof(kName1))));