diff --git a/examples/platform/silabs/SilabsDeviceDataProvider.cpp b/examples/platform/silabs/SilabsDeviceDataProvider.cpp index 6dbe34e097daf4..eb0f8fee82ff1c 100644 --- a/examples/platform/silabs/SilabsDeviceDataProvider.cpp +++ b/examples/platform/silabs/SilabsDeviceDataProvider.cpp @@ -18,6 +18,7 @@ #include "SilabsDeviceDataProvider.h" #include #include +#include #include #include #include @@ -391,6 +392,8 @@ CHIP_ERROR SilabsDeviceDataProvider::GetHardwareVersionString(char * buf, size_t if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { VerifyOrReturnError(buf != nullptr, CHIP_ERROR_NO_MEMORY); + VerifyOrReturnError(bufSize > strlen(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), + CHIP_ERROR_BUFFER_TOO_SMALL); Platform::CopyString(buf, bufSize, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); err = CHIP_NO_ERROR; }