Skip to content

Commit 17710f1

Browse files
adds literal length check (#41478)
1 parent c15b122 commit 17710f1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/include/platform/internal/GenericConfigurationManagerImpl.ipp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,31 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetCommissionableDevice
673673
template <class ConfigClass>
674674
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetInitialPairingInstruction(char * buf, size_t bufSize)
675675
{
676-
VerifyOrReturnError(bufSize >= sizeof(CHIP_DEVICE_CONFIG_PAIRING_INITIAL_INSTRUCTION), CHIP_ERROR_BUFFER_TOO_SMALL);
676+
constexpr size_t kLiteralSize = sizeof(CHIP_DEVICE_CONFIG_PAIRING_INITIAL_INSTRUCTION);
677+
constexpr bool kIsLiteralEmpty = (kLiteralSize == 1); // Only the null terminator is present, the literal is "" (empty-string)
678+
679+
if (kIsLiteralEmpty)
680+
{
681+
return CHIP_ERROR_NOT_FOUND;
682+
}
683+
684+
VerifyOrReturnError((bufSize >= kLiteralSize), CHIP_ERROR_BUFFER_TOO_SMALL);
677685
strcpy(buf, CHIP_DEVICE_CONFIG_PAIRING_INITIAL_INSTRUCTION);
678686
return CHIP_NO_ERROR;
679687
}
680688

681689
template <class ConfigClass>
682690
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetSecondaryPairingInstruction(char * buf, size_t bufSize)
683691
{
684-
VerifyOrReturnError(bufSize >= sizeof(CHIP_DEVICE_CONFIG_PAIRING_SECONDARY_INSTRUCTION), CHIP_ERROR_BUFFER_TOO_SMALL);
692+
constexpr size_t kLiteralSize = sizeof(CHIP_DEVICE_CONFIG_PAIRING_SECONDARY_INSTRUCTION);
693+
constexpr bool kIsLiteralEmpty = (kLiteralSize == 1); // Only the null terminator is present, the literal is "" (empty-string)
694+
695+
if (kIsLiteralEmpty)
696+
{
697+
return CHIP_ERROR_NOT_FOUND;
698+
}
699+
700+
VerifyOrReturnError((bufSize >= kLiteralSize), CHIP_ERROR_BUFFER_TOO_SMALL);
685701
strcpy(buf, CHIP_DEVICE_CONFIG_PAIRING_SECONDARY_INSTRUCTION);
686702
return CHIP_NO_ERROR;
687703
}

0 commit comments

Comments
 (0)